Convert string to date format in XSLT

I have a date (string) value in an XML file in this format:

Tue Apr 17 03:12:47 IST 2012 

I want to use XSL conversion to convert string / date to this format:

 4/17/2012 03:12:47 AM 

How can I do this in my XSL transform?

+8
xml xslt date-format transform
source share
1 answer

If you use

But my suggestion is

You have a standard XSD date and time format for XML, based on the code (i.e. at the time of rendering) you can format as you like.

Update:

Always process XML through XSLT; dates must be in standard XSD format. Your input is currently not in the standard format, so it throws an error.

Example:

 <xsl:variable name="dt" as="xs:dateTime" select="xs:dateTime('2012-10-21T22:10:15')"/> <xsl:value-of select="format-dateTime($dt, '[Y0001]/[M01]/[D01]')"/> 

OUTPUT:

2012/10/21

+20
source share

All Articles