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)}
Are you in Sydney?
Yes.
K, just checking first! I'm on my phone so can't verify the rest. Let me respond later or tomw. I suspect (well, know) that the stored value has a different offset than what's displayed in SFDC, so you have to account for that.
Thanks Sanford, this has worked!
Great. I'm going to do a short blog post on this as it seems to frequently be done incorrectly (people think their Velo tz and instance/Admin tz are the same).
Hi Sanford Whiteman
Im sorry to ask a silly question but how to I apply this to a token on a landing page
Thanks
In an LP, where Velocity is not available, you can use a tz-aware library like Moment-Timezone.
Thanks Sanford, this is great!