Formatting date of velocity token from custom object
Hello,
I'm trying to figure out how to format a date on a custom object. I've seen other posts, but am not finding one that is addressing my specific use case... and if it is, I'm not understanding what I need to change to make it work.
Here is what I started with and it is pulling the date, just not in the format I want/need:
#if( !$customList_cList.isEmpty() )
#foreach( $customList in $customList_cList )
#if( $customList.listID.equals("Returned Item") && !$customList.date1.isEmpty() )
#set( $myDate = $customList.date1 )
#break
#end
#end
#end
${myDate}
Looking at the community and seeing posts from @sanfordwhiteman, I know that I need to incorporate time zones and the like... I found a post that looked similar to what I wanted to do and I ended up with this:
#set( $dateOptions = {
"formats" : {
"userin" : "yyyy-MM-dd",
"userout" : "m d, yyyy"
},
"timezones" : {
"userin" : "America/Los_Angeles",
"userout" : "America/Los_Angeles"
},
"locale" : $date.getLocale()
} )
#set( $transactionDatelike = $customList_cList.get($lastIndex).date1 )
#set( $transactiontDate = $convert.parseDate(
$transactionDatelike,
$dateOptions.formats.userin,
$dateOptions.locale,
$date.getTimeZone().getTimeZone($dateOptions.timezones.userin)
) )
## convert the date to a different format
#set( $transactionDate_formatted = $date.format(
$dateOptions.formats.userout,
$transactionDate,
$dateOptions.locale,
$date.getTimeZone().getTimeZone($dateOptions.timezones.userout)
) )
$transactionDate_formatted
But I know this isn't going to work, because it's not looking for the Custom List with a List ID of "Returned Item", and it's just spitting out the token value at the end when I test it.
Advice on how to fix this so that it displays the date in m d, yyyy format?