JEMH velocity context, relating to emails (comment header specifically) has $sentDate (if present, reverts to now() if not) as well as $receivedDate.  Presentation of these dates can be altered through helper classes in the velocity context.

Lower down there are several date operators that are hyperlinked to API Documentation so you know what you can do with them:

For example:

1a) $dateFormatter.format($sentDate)
1b) $dateFormatter.forLoggedInUser().withStyle($dateTimeStyle.RSS_RFC822_DATE_TIME).format($sentDate)
1c) $dateFormatter.forLoggedInUser().withStyle($dateTimeStyle.DATE_TIME_PICKER).format($sentDate)
1d) $dateFormatter.forLoggedInUser().withStyle($dateTimeStyle.RELATIVE).format($sentDate)
2) $outlookdate.formatDMY($sentDate) $outlookdate.formatTime($sentDate)
3) $dateformatter.getNow() / $dateformatter.formatIso8601($dateformatter.getNow()) 
4) $dateTimes.formatRSS($sentDate)

Generates:

1a) 16/Jan/15 10:47 AM
1b) Fri, 16 Jan 2015 10:47:48 +0000
1c) 16/Jan/15 10:47 AM
1d) Today 10:47 AM
2) 16/Jan/15 10:47 AM
3) Fri Jan 16 10:47:48 GMT 2015 / 2015-01-16T10-47
4) Fri, 16 Jan 2015 10:47:48 +0000

Velocity Custom Field Dates

JEMH can build date objects too, to enable values to be generated for arbitrary dates, e.g.:

Date Time
#set($longVal = $currentMillis.longValue() + 86400000 )
$dateFormatter.format($jemhDateUtils.createDate($longVal))

Example Output:

29/Mar/15 3:41 PM

Date Only
#set($longVal = $currentMillis.longValue() + 86400000 )
$dateFormatter.formatDMY($jemhDateUtils.createDate($longVal))

Example Output:

29/Mar/15

DatePicker custom fields

$dateFormatter.formatDatePicker($issue.getCustomFieldValue("customfield_10700"))

For further Date formatting options please see:

JEMHDateUtils

JEMHDateUtils is another interface written by JEMH to accommodate certain functionality which is not achievable when working with Dates obtained from the email.

#set ($headerDate = "Wed, 19 Feb 2020 14:50:59 +0000")
#set ($dateFormat = "E, d MMM yyyy HH:mm:ss Z")
#set ($date = $jemhDateUtils.getZonedDateTime($headerDate, $dateFormat))
The date/time in the email is: $date.format($jemhDateUtils.getFormatter($dateFormat))

#set ($zone = $jemhDateUtils.getZoneId("America/Los_Angeles"))
#set ($laTime = $date.withZoneSameInstant($zone))
In Los Angeles this is: $laTime.format($jemhDateUtils.getFormatter($dateFormat))

Debugging velocity rendered custom fields as above is a bit tedious (issue JEMH-7794 logged to pick and evaluate script against a stored JEMH Test Case email). For rapid testing against a Test Case, you can do the same thing in a Script Field Processor edit window:

if (message.getHeader("Date") !=null)
{
 var headerDate = message.getHeader("Date")[0];
 var dateFormat = "E, d MMM yyyy HH:mm:ss Z";
 var date = jemhDateUtils.getZonedDateTime(headerDate, dateFormat);

print ('The date/time in the email is: ' +date.format(jemhDateUtils.getFormatter(dateFormat)) );

 var zone = jemhDateUtils.getZoneId("America/Los_Angeles");
 var laTime = date.withZoneSameInstant(zone);

print ('In Los Angeles this is: '+laTime.format(jemhDateUtils.getFormatter(dateFormat)) );
}
else
{
    print ('no Date: header');
}

The key functionality to note:

Output:

The date/time in the email is: Wed, 19 Feb 2020 14:50:59 +0000
In Los Angeles this is: Wed, 19 Feb 2020 06:50:59 -0800

Creating relative dates in custom fields

@since 3.3.27

This set of methods doesn’t depend on any Jira user in the authentication context, e.g., you want to do date/time manipulation for a custom field default

$jemhDateUtils.createLocalDate().plusDays(15).format($jemhDateUtils.getFormatter("dd/MMM/yy"))

If you want to use the Jira format:

#set ($javaDateFormat = $applicationProperties.getDefaultBackedString("jira.date.picker.java.format"))
#set ($formatter = $jemhDateUtils.getFormatter($javaDateFormat))
$jemhDateUtils.createLocalDate().plusDays(14).format($formatter)

Related articles

Related articles appear here based on the labels you select. Click to edit the macro and add or change labels.

Related issues