Convert Date/Time as per User's Timezone

Srivignesh
Level 2

Convert Date/Time as per User's Timezone

Hello Everyone,

 

We are using below velocity script in the token created for a custom object which has date as data type. Based on user's location, out time zone will be updated with Country/City to populate exact date in the email communication sent to users. It populates correct date for the countries we checked but only for Canada, the populated date is not matching with user's data. If user data is 29/03/2022 1:45 AM, it populates as 28/03/2022 3:15 PM. In velocity script, America/Toronto is updated in out time zone as below for Canada user and tried updating with different cities as well, still getting data mismatch issue. Any suggestions to populate data as expected?

Velocity Script: 

#foreach( $Application in $sorter.sort($application_cList,['bookingDate:desc']))
#if($foreach.count<=1)
#set($inTimeZone=$date.getTimeZone().getTimeZone('America/Chicago'))
#set($outTimeZone=$date.getTimeZone().getTimeZone('America/Toronto'))
#set($locale=$date.getLocale())
#set($myDate=$convert.parseDate(${Application.bookingDate},'yyyy-MM-dd',$locale,$inTimeZone))
${date.format('MMMM dd, yyyy',$myDate,$locale,$outTimeZone)}
#end
#end


Regards,
Srivignesh B.

2 REPLIES 2
Jo_Pitts1
Level 10 - Community Advisor

Re: Convert Date/Time as per User's Timezone

@Srivignesh ,

what do you mean by a 'data mismatch issue'.

What output are you getting.

 

regards

Jo

Srivignesh
Level 2

Re: Convert Date/Time as per User's Timezone

@Jo_Pitts1  Thanks for your response. The user data in the system is 29/03/2022 1:45 AM and the output populates as 28/03/2022 3:15 PM instead of showing 29/03/2022.

Thanks,

Srivignesh B.