xslt - Convert 12 hour format date into 24 hour in XSLT1.0 or XSLT2.0 -
i need convert date 12 hour format 24 hour format.
input: 01/27/2016 07:01:36 pm
expected output: 201601271901(yyyymmddhhmm)
i have used format-datetime() function in code ,i getting error
<xsl:value-of select="format-datetime(part_need/promised_dt,'[y0001][m01][d01][h01][m01]')"/>
error:
description: forg0001: invalid datetime value "01/27/2016 07:01:36 pm" (non-numeric year component)
please on issue
your input not valid iso 8601 date/time, cannot use built-in date/time functions on it.
try instead (xslt 2.0):
<xsl:template match="inputdate"> <xsl:copy> <xsl:variable name="dte" select="tokenize(.,'/|\s|:')" /> <xsl:value-of select="$dte[3]" /> <xsl:value-of select="$dte[1]" /> <xsl:value-of select="$dte[2]" /> <xsl:variable name="h24" select="xs:integer($dte[4]) mod 12 + 12 * xs:integer($dte[7]='pm')" /> <xsl:value-of select="format-number($h24, '00')" /> <xsl:value-of select="$dte[5]" /> </xsl:copy> </xsl:template>
note assumes days zero-padded 2 digits (as months).
if need use in several places, consider turning function.
Comments
Post a Comment