Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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

Table of Contents

Formatting is done in two steps:

  1. create a formatter object
  2. format the date or date-time values using the created formatter

Create Jira Formatter

Create a Jira formatter in your template:

Code Block
#set($formatter = $!jetiFieldFormatter.getJiraDateTimeFormatter(<date time style name>))

<date time style name> may be any of the following:

  • empty: if called without a parameter, getJiraDateTimeFormatter() returns the default Jira date time formatter
  • name of a predefined style in DateTimeStyle: e.g. $!jetiFieldFormatter.getJiraDateTimeFormatter("COMPLETE") returns a Jira formatter for the COMPLETE style

Create Java Formatter

There are multiple ways to create Java date formatter.

Code Block
titleCreate Java formatter with style
#set($formatter = $!jetiFieldFormatter.getJavaDateFormat(<date format style number>, <locale string>))

<date format style number> may be any of the following:

  • empty: if called without parameters getJavaDateFormat() returns the default Java formatter
  • value of a date format style constant in DateFormat: e.g. $!jetiFieldFormatter.getJavaDateFormat(1) returns a DateFormat instance for the DateFormat.LONG style.

<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.

Code Block
titleCreate Java formatter with pattern
#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".

 

Format Values

Once we have a formatter, date or date-time field values can be formatted as shown below.

Code Block
$!jetiFieldFormatter.formatSafely($formatter,<date time value>)

<date time value> may be either:

  • Issue attribute, like $!issue.created or $!issue.updated
  • Issue custom field: $!issue.getCustomFieldValue("customfield_12345"), where "customfield_12345" is the custom field key of a Date Picker or DateTime Picker field. Calling the formatter with a non-date value will render an empty string

Render Date or Date-Time Values in any time zone

To render Date or Date-Time values in a time zone, 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:

Code Block
##Create a Java formatter using a java datetime pattern
#set($formatter = $!jetiFieldFormatter.getJavaDateTimeFormat("yyyy.MMM.dd z"))

##set the time zone 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:

Code Block
##Create a Java formatter using a Jira formatter style, with the time zone 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)

Render Date or Date-Time Values in your time zone

We support using the time zone set in the current user’s profile. For example to render the issue's last update date-time with the current user's time using the TemplateSupport's currentUsersTimeZoneId

Code Block
##give dynamically the time zone upon the current user's profile using the shortcut template method #renderDateTime 
The issue was updated at #renderDateTime($!issue.updated "yyyy-MM-dd'T'HH:mmZ'['z']'" $!templateSupport.currentUsersTimeZoneId)Please note that the capital letter T in the above code is just a placeholder, an example to mark that after the date, the time value comes next.

Shortcut Template Methods to Format Values easier

...

Redirect
filename
locationhttps://docs.meta-inf.hu/email-this-issue-for-jira-server-data-center/documentation/outgoing-emails/email-templates/formatting-date-and-time-values

Thank you for visiting our old product documentation site. Note that we no longer store or update our documentation here.

Please navigate to our new documentation site and update your bookmarks accordingly. If you're looking for the former content of this page, click here.