Date time formats in Velocity script
Hi
I'm working with date times in Velocity and struggling to get a date to display in the correct format. I have an incoming date string in the format: '2023-04-04T13:00:00Z'. So the incoming time is 1300 UTC which is 1400 BST
I'm using @sanfordwhiteman examples from here: https://blog.teknkl.com/velocity-days-and-weeks/
And wanted to get the date to display as:
Tuesday 4 April 14:00 BST
But it displays as 13:00 BST instead. Here is my sample code, note the line:
#set( $ISO8601DateTimeUTC = "yyyy-MM-dd'T'HH:mm:ss'Z'" )
is not taken from Sanford's blog which I think is the problem, as it seems it's not recognising the format at UTC and rather just a TZ unaware format. Full sample code:
#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("Europe/London") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateTimeUTC = "yyyy-MM-dd'T'HH:mm:ss'Z'" )
#set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" )
#set( $ISO8601DateTimeWithMillisTZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )
##set input date
#set($input_date = '2023-04-04T13:00:00Z')
##convert input date
#set( $input_date = $convert.toCalendar(
$convert.parseDate(
$input_date,
$ISO8601DateTimeUTC,
$defaultLocale,
$defaultTimeZone
)
) )
##set date formats
#set($format_display = "EEEE d MMMM HH:mm z" )
##OUTPUT
Display format:<br/>
$date.format($format_display,$input_date,$defaultLocale,$defaultTimeZone)
Thanks!