Himanshu Yadav
Himanshu Yadav

Reputation: 13587

XSLT: Current date time long fromat with millisecond

I have upgraded XSLT processor. And getting the current date time. But it is not in desired format.

<xsl:value-of select="format-dateTime(current-dateTime(), '[Y,4][D,2][M,2] [H]:[m]:[s]:[f01] [Z]')" />

gives

20132409 14:03:17:54 -04:00

But I want in long format with milliseconds. Something like 1346498794643

Upvotes: 4

Views: 11482

Answers (1)

G. Ken Holman
G. Ken Holman

Reputation: 4393

I hope I've remembered the epoch correctly:

T:\ftemp>xslt2 milliseconds.xsl milliseconds.xsl
<?xml version="1.0" encoding="UTF-8"?>1380039731273
T:\ftemp>type milliseconds.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="xs"
  version="2.0">

<xsl:template match="/">
  <xsl:value-of select="( current-dateTime() -
                          xs:dateTime('1970-01-01T00:00:00') )
                        div xs:dayTimeDuration('PT1S') * 1000"/>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>

Recall that in XSLT the current date and time is a static value for the duration of the transformation. You will get the same value for every time you invoke this function in a single invocation of a given stylesheet.

Upvotes: 5

Related Questions