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 transformation to convert the string/date into this format:
4/17/2012 03:12:47 AM
How can I do that in my XSL transform?
Can use the following conversion code to convert UTC format string to any other DateTime format. string result = Convert. ToDateTime("2011-02-04T00:00:00+05:30"). ToString("MM/dd/yyyy h:mm:ss tt");
Inputs. The substring() function takes a string and one or two numbers as arguments. The string is the string from which the substring will be extracted. The second argument is used as the starting position of the returned substring, and the optional third argument specifies how many characters are returned.
The Replace function works by writing an XSLT template for this function and calls this replace whenever replacement of the string action is required. This function is very similar to regex-group ().
If you are using
XSLT 1.0 version, use EXSLT - date:format-date date extension
XSLT 2.0 version, use built-in: Formatting Dates and Times date extension
But my suggestion is to
Have a standard XSD datetime format on XML, on the code-behind (that is, on rendering time) you can format as you like.
Always XML to process through XSLT, dates should be in standard XSD format. Currently your input is not in standard format so that it throws 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With