I have an XML that has timestamp in format like 2016-06-07T07:46:04
I would like to convert timestamp in UTC format like 1465278364 using xslt
How can it be done?
Thanks in advance.
I have an XML that has timestamp in format like 2016-06-07T07:46:04
I would like to convert timestamp in UTC format like 1465278364 using xslt
How can it be done?
Thanks in advance.
I actually wrote a named template specifically for this a while back. Here it is:
This adds up:
All of the above is then multiplied by the number of seconds in a day Then it's just a simple matter of adding hours * (seconds in an hour), minutes * (seconds in a minute) and seconds.
You can support different date formats just by putting a different
<xsl:when>
element with a different date pattern, and obviously adjusting the substring calls to match.Honestly though, only use this if you can't use XSLT 2.0 (or later) or an extension function. Also, I noticed the number you gave is 7200 seconds out from what this produces, but if you're in a time zone 2 hours different from UTC, that's probably why.