...
Status | ||||
---|---|---|---|---|
|
JEMHDateUtils is another interface written by JEMH to accommodate certain functionality which is not achievable when working with Dates obtained from the email.
Code Block |
---|
#set ($headerDate = "Wed, 19 Feb 2020 14:50:59 +0000") #set ($dateFormat = "E, dd MMM yyyy hhHH:mm:ssZ") #foreach($headerDate in $message.getHeader("date")) ss Z") #set ($ukDate$date = $jemhDateUtils.stringToDategetZonedDateTime($dateFormat, "Europe/London", $headerDate)) #set ($localisedDateStr = $jemhDateUtils.localiseDate($ukDate, "America/Los_Angeles")) #set ($localisedDate$headerDate, $dateFormat)) The date/time in the email is: $date.format($jemhDateUtils.getFormatter($dateFormat)) #set ($zone = $jemhDateUtils.stringToDate("yyyy-MM-dd'T'HH:mm:ss", getZoneId("America/Los_Angeles", $localisedDateStr)) #set ($formattedDate$laTime = $jemhDateUtils$date.formatDate("dd/MM/yyyy hh:mm aa", $localisedDate)) Header date: $headerDate ($headerDate.class) UK Date: $ukDate ($ukDate.class) Los Angeles Date: $localisedDate ($localisedDate.class) Formatted Date for Los Angeles: $formattedDate ($formattedDate.class) #end |
Example Output:
Code Block |
---|
Header date: Sun, 19 Jun 2011 17:42:26 +1200 (class java.lang.String)
UK Date: Sun Jun 19 06:42:26 BST 2011 (class java.util.Date)
Los Angeles Date: Sat Jun 18 22:42:26 BST 2011 (class java.util.Date)
Formatted Date for Los Angeles: 18/06/2011 10:42 PM (class java.lang.String) |
...
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:
Code Block |
---|
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 |
Related articles
Filter by label (Content by label) | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...