Set local timezone using Velocity scripts | Community
Skip to main content
September 2, 2016
Solved

Set local timezone using Velocity scripts

  • September 2, 2016
  • 2 replies
  • 12749 views

Hi all.

I am trying to use a script and Velocity to make the output of a date/time field more user friendly.

$date.format('MMMM dd, yyyy hh:mm a z', ${convert.parseDate(${lead.pexa_callbacktime}, 'yyyy-MM-dd')})

I am using the following Velocity script to achieve this, and so far I can successfully change the format, however it changes the timezone on me to GMT.  We are in Australia so need this to display AEST (or GMT+10).

The output i get is as follows.

Original Date/Time - 2016-09-14 11:00:00

Output after running through the above script - September 14, 2016 12:00 AM GMT

Any pointers on how to set the location or time zone in the output?  I am assuming this is picking up the timezone of Marketo's Apache server.

Thanks

Nick

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

When you first parse the Date from the string (inbound) include the timezone, and remember to include the time itself (you don't have it in your format pattern).

Instantiate the output timezone -- in the below snippet, in and out are the same -- and format the new string (outbound) with that timezone.

#set( $inTimeZone = $date.getTimeZone().getTimeZone('Australia/Sydney') )

#set( $outTimeZone = $date.getTimeZone().getTimeZone('Australia/Sydney') )

#set( $locale = $date.getLocale() )

#set( $myDate = $convert.parseDate($lead.pexa_callbacktime,'MM-dd-yy HH:mm:ss',$locale,$inTimeZone) )

${date.format('MMMM dd, yyyy hh:mm a z',$myDate,$locale,$outTimeZone)}

2 replies

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
September 2, 2016

When you first parse the Date from the string (inbound) include the timezone, and remember to include the time itself (you don't have it in your format pattern).

Instantiate the output timezone -- in the below snippet, in and out are the same -- and format the new string (outbound) with that timezone.

#set( $inTimeZone = $date.getTimeZone().getTimeZone('Australia/Sydney') )

#set( $outTimeZone = $date.getTimeZone().getTimeZone('Australia/Sydney') )

#set( $locale = $date.getLocale() )

#set( $myDate = $convert.parseDate($lead.pexa_callbacktime,'MM-dd-yy HH:mm:ss',$locale,$inTimeZone) )

${date.format('MMMM dd, yyyy hh:mm a z',$myDate,$locale,$outTimeZone)}

September 2, 2016

Thanks Sanford, this is great!

Mark_Wallace1
Level 4
July 3, 2018

Hello All

Just discovered this and found I can put a webinar into the contacts local timezone using the person time zone field value.  Fantastic.

Wanted to check is it possible to put the local campaign tokens into the velocity script.  Im currently including the webinar times by putting the webinar times into a field, when they are already in a local token.

If I could put the webinar start time token into the script that would make my day.

thanks for this

SanfordWhiteman
Level 10
July 3, 2018

What do you mean by "local campaign tokens"?  The built-in {{campaign.tokens}}?