Search code examples
datexslt-2.0gmt

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?


Solution

  • 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.