Email this issue gives you full control in formatting date and time values in your email templates. Email This Issue provides a component that you can use in the email templates. It is called $!jetiFieldFormatter.
View methods of this component in Velocity Context in Email Rendering.
Formatting is done in two steps:
Create a Jira formatter in your template:
#set($formatter = $!jetiFieldFormatter.getJiraDateTimeFormatter(<date time style name>)) |
<date time style name> may be any of the following:
There are multiple ways to create Java date formatter.
#set($formatter = $!jetiFieldFormatter.getJavaDateFormat(<date format style number>, <locale string>)) |
<date format style number> may be any of the following:
<locale string>: Java string representation of a Locale, always use language and country, like "en_GB" or "de_DE" or "hu_HU". This parameter is optional. If not provided, user's default locale will be used.
#set($formatter = $!jetiFieldFormatter.getJavaDateTimeFormat(<date type pattern>)) |
<date time pattern> can be a valid pattern according to Java SimpleDateFormat specification.
E.g. a pattern of "dd/MM/yyyy HH:mm" returns a formatter that formats the timestamp of May 31, 2015 1:35pm as "31/05/2015 13:35".
Once we have a formatter, date or date time field values can be formatted as shown below.
$!jetiFieldFormatter.formatSafely($formatter,<date time value>) |
<date time value> may be either:
To render Date or Date Time values in a timezone, both the Jira DateFormatter and Java DateFormat may be used. There is a list of Timezone IDs are available for java.
Render the Issue's due date in Alaska time using the Java DateFormat API:
##Create a Java formatter using a java datetime pattern #set($formatter = $!jetiFieldFormatter.getJavaDateTimeFormat("yyyy.MMM.dd z")) ##set the timezone in the formatter $!formatter.setTimeZone($!jetiFieldFormatter.getTimeZone("US/Alaska")) ##format the date value with the formatter Issue Due Date in Alaska time: $!formatter.format($!issue.dueDate) |
Render the Issue's due date in Alaska time using the Jira DateFormatter API:
##Create a Java formatter using a Jira formatter style, with the timezone information #set ($formatter = $jetiFieldFormatter.getJiraDateTimeFormatter("COMPLETE").withZone($!jetiFieldFormatter.getTimeZone("US/Alaska"))) ##format the date value with the formatter Issue Due Date in Alaska time: $!formatter.format($!issue.dueDate) |
#renderDateTime($!issue.getCustomFieldValue("My Date Time Custom Field") "yyyy-MM-dd") ##Render the issue's "My Date Time Custom Field" custom field in the given pattern #renderDate($!issue.dueDate "yyyy-MM-dd") ##Render the issue's due date in the given pattern #renderDate($!issue.dueDate "yyyy-MM-dd" "US/Alaska") ##Render the issue's due date in the given pattern using Alaska timezone #renderDateTime($!issue.getCustomFieldValue("My Date Time Custom Field") "yyyy-MM-dd") ##Render the issue's "My Date Time Custom Field" custom field in the given pattern #renderDateTime($!issue.getCustomFieldValue("My Date Time Custom Field") "yyyy-MM-dd" "US/Alaska") ##Render the issue's due date in the given pattern with regard to the given timezone |