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, eg:
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.withStyle($dateTimeStyle.DATE).format($jemhDateUtils.createDate($longVal))
Example Output:
29/Mar/15
JEMHDateUtils
SINCE 3.2.6
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, dd 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))
The key functionality to note:
ZonedDateTime - we are using ZonedDateTime which allows us to retain the timezone aspect along with the date + time. This is vital aspect in case you’d wish to convert this to another timezone (which is what is being done in the above example)
Formatter - to format the date in a certain pattern (i.e. 12/02/2020 - 08:29), we have provided the getFormatter(pattern) method which is responsible for returning a DateTimeFormatter. The same can be used to format the ZonedDateTime to any other preferred format
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