Unable to use formatDate function in v1 email template

Hi developers,

We have a situation where we require to use different timezone (MYT) in email template. As per the documentation, we can convert timezone only in v2 templates.

By right, formatDate function should work in v1 templates. However, $spTools.formatDate() is also not working for the template of “Access Request Decision for Other”. Maybe due to the date is returned in string format. I still need a way to convert timezone.

  • How can I achieve updating time and date in this template?
  • When this template be changed to v2?

Hi Sanjeevan,

This post should help your case - Email Template V1 date format timezone issues - Certification Reassignment - #6 by notjavadev

Thanks,
Shailee

Hey @jeev1,
To see the object type, you can add getClass().getName() on the object itself. For example, in your case, it could be:
Remove Date Class:$detail.removeDate.getClass().getName()

Assign a test role with expiration date to someone to test this. If the type is indeed a string, use SimpleDateFormat class to first parse it into a date object and then format this date object in whichever format you need. So the steps would be:

  1. Get SimpleDateFormat class
    #set($sdf = $spTools.getClass().forName("java.text.SimpleDateFormat"))

  2. Initialize class instance and set the pattern to the input date string pattern (the input value format is what toString on a date object prints i.e. “EEE MMM dd HH:mm:ss z yyyy”):
    #set($pattern = $sdf.newInstance()) $pattern.applyPattern("EEE MMM dd HH:mm:ss z yyyy")

  3. Parse the input date string into a date object:
    #set($removeDate = $pattern.parse($detail.removeDate)

Use this date object in the rest of your template as you need.

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