How to convert 2002-05-30T09:30:10-06:00 to Unix time stamp using xslt 2.0 -
this logic trying use .should sub string 2002-05-30t09:30:10-06:00 , 2002-05-30t09:30:10 , 06:00 separate , subtract , use in below logic.if there easier way kindly let me know. {code}
<tns:timestamp> <xsl:variable name="date" select="/order/@orderdate"/> <xsl:value-of select='xs:datetime("1970-01-01t00:00:00") + @date *xs:daytimeduration("pt0.001s")'/> </tns:timestamp>
i don't think should subtract offset in calculation. if do:
(xs:datetime(@orderdate) - xs:datetime('1970-01-01t00:00:00z')) div xs:daytimeduration('pt1s') the result be:
1022772610 if convert unix time human readable time correct gmt , local time:
here's example (see working here)...
xml input
<order orderdate="2002-05-30t09:30:10-06:00"/> xslt 2.0
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:xs="http://www.w3.org/2001/xmlschema" exclude-result-prefixes="xs"> <xsl:output indent="yes"/> <xsl:template match="/order"> <order unix-time="{(xs:datetime(@orderdate) - xs:datetime('1970-01-01t00:00:00z')) div xs:daytimeduration('pt1s')}"> <xsl:copy-of select="@*|node()"/> </order> </xsl:template> </xsl:stylesheet> xml output
<order unix-time="1022772610" orderdate="2002-05-30t09:30:10-06:00"/> 
Comments
Post a Comment