Email template with custom timezone in date value

Hi IDN Experts,

Is there any way to specify a customized timezone (like NZT) instead of GMT in the email template? Using the default $__dateTool only gives the date time value in GMT timezone which is not quite friendly.

Ronald

Hi @ronaldchuiASB

Did you consider using Apache Velocity script to further customize your date value ?

Thanks
Krish

Hi @ronaldchuiASB , as Krishna mentioned above, you can use Apache Velocity to achieve the desired time zone.

Using DateTool’s format method, you can format your GMT time zone value to NZT time zone value. The format method (in below link) can be referred:
https://velocity.apache.org/tools/devel/apidocs/org/apache/velocity/tools/generic/DateTool.html

HTH!

Hi Krish and Gaurav,

Thanks for the suggestion. I did tried to reformat using the DateTool from velocity before I posted this thread, but not able to give desired results.

#set($_startDate = $__dateTool.toDate(“yyyy-MM-dd’T’HH:mm:ss”, ${startDate}, Locale.US, TimeZone.getTimeZone(“Pacific/Auckland”)))

Do you have any example to change the output to NZT time zone value? Thanks.

Ideally this would be customized to the recipient based on their identity settings for their local timezone like they see when things are presented in the UI.

Hi Ed,

Not quite…
I tried to print out the time zone using “$__dateTool.getTimeZone()” in email template it is always GMT and I cannot find any way to set to different time zone.
It will be great if you can shed some lights on how I can display the date in different time zone instead of GMT. Thanks.

Ronald

Having done a few Google-ing and finally got the solution from

sample syntax:

$dateTool.format("yyyy-MM-dd'T'HH:mm:ss", $dateTool, $dateTool.getLocale(), $dateTool.getTimeZone().getTimeZone("NZ"))

Thank you all
Ronald

2 Likes

@ronaldchuiASB My comment was based on how a competitor (Omada) does this. They actually look at the TZ of the intended recipient (via their user account record) and display the result in the user specific TZ vs. system TZ, admin user TZ, etc.

Hi @ronaldchuiASB , thanks for posting the solution.
We have a similar use case to convert the time zone for expiration date in certification kickoff notification. The syntax you shared is somehow not working for us, below is what we used,

$date.format(“yyyy-MM-dd HH:mm:ss.SSS a zzzz”, $date.getDate(), $date.getLocale(), $date.getTimeZone().getTimeZone(‘EST’)) – This is taking current date to convert into EST timezone

$date.format(“yyyy-MM-dd HH:mm:ss.SSS a zzzz”, $certification.expiration, $date.getLocale(), $date.getTimeZone().getTimeZone(‘EST’)) – This is taking expiration date to convert into EST timezone

Could you please suggest. Thanks

Not sure if Im doing anything wrong but dateTool never worked for me.

Even importing it explictly with #set($dateTool = $tool.date) doesnt do anything

@aditya_pathak , you can refer to the documentation. The “__dateTool” is a built-in variable that we can use for date formatting.

You can then refer to the DateTool documentation for details
https://velocity.apache.org/tools/2.0/apidocs/org/apache/velocity/tools/generic/DateTool.html

@rpriya I’m not sure why it does not work for you. Have you checked if you have provided correct value for the format function? What I can see is, the second argument I used is the $dateTool object, while you are using the date object, not sure if it is the cause.

I am using the built-in variable $__dateTool to do the formatting, not sure if your $date is the same as that. You can refer to the DateTool documentation for details
https://velocity.apache.org/tools/2.0/apidocs/org/apache/velocity/tools/generic/DateTool.html

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.