CuriosityKills
CuriosityKills

Reputation: 56

How to get RFC1123 Date format for current date time using XSLT 2.0

I am trying to retrieve current date time in RFC1123 date format in XSLT. has anybody tried this using XSL2.0?

I have seen code for converting various date times based on zone in XSLT2.0 and to format in specific date time format such yyyy/mm/dd or YYYY:MM:DDTHH:MM:SS.0Z, but couldnt find a way to format it to show like this

Tue, 09 Jul 2019 20:34:29 GMT

concat(date:add('1970-01-01T00:00:00',concat('PT',floor(dp:time-value() div 1000),'S')),':',dp:time-value() mod 1000)

This returns in GMT format like this 2019-07-09T21:01:26:547

How to format it for - Tue, 09 Jul 2019 20:34:29 GMT using XSLT2.0?

Upvotes: 0

Views: 1343

Answers (2)

CuriosityKills
CuriosityKills

Reputation: 56

Thanks for quick reply, your solution worked using Altova XML Spy, but unfortunately it didnt worked for me in Datapower using XSLT2.0, Not sure what was wrong, may be some issue with DP firmware version.

just for other users to make this post more helpful. I tried below 2 options which didnt work for me, but might be useful for others.

using XSLT

<xsl:value-of select="java:java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneOffset.UTC))"></xsl:value-of>

<xsl:value-of select="format-dateTime(current-dateTime(), '[FNn,*-3], [D01] [MNn] [H01]:[m01]:[s01] [z]')"/>

So I used Gateway script to get same date format which I was looking for and stored in context variable using below

var dateNeeded = new Date()).toUTCString(); //Thu, 11 Jul 2019 21:08:12 GMT

Upvotes: 0

Martin Honnen
Martin Honnen

Reputation: 167716

Use current-dateTime() to get the current date and time and then use format-dateTime to format it as needed, see the spec https://www.w3.org/TR/xslt20/#function-format-dateTime on details: a picture string

'[FNn,*-3], [D01] [MNn] [H01]:[m01]:[s01] [z]'

on my machine in German summer time gives

format-dateTime(current-dateTime(), '[FNn,*-3], [D01] [MNn] [H01]:[m01]:[s01] [z]')

as

Wed, 10 July 12:01:13 GMT+02:00

This is meant as an example on the use of format-dateTime, I haven't checked the exact details of the RFC you cited to try to implement the exact requirements.

Upvotes: 0

Related Questions