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
Solved! Go to Solution.
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)}