views:

171

answers:

1

Hi.

I have a dateTime variable, and I want to convert it to a decimal value of epoch. How can this be done?

I tried using:

seconds-from-duration($time, xs:dateTime('1970-01-01T00:00:00'))

but it just returns 0.

Please advice. Thanks.

+4  A: 

This transformation:

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    <xsl:output method="text"/>

 <xsl:template match="/">
   <xsl:sequence select="current-dateTime()"/>

   <xsl:sequence select=
   "( current-dateTime() - xs:dateTime('1970-01-01T00:00:00') )
    div
     xs:dayTimeDuration('PT1S')
     "/>
 </xsl:template>
</xsl:stylesheet>

when applied on any XML document (not used), produces the wanted result -- the current date-time and its Unix epoch (the number of seconds since 1/1/1970 ):

2010-08-12T06:26:54.273-07:00    1281594414.273
Dimitre Novatchev
This is great! works like magic. Thanks a lot.
Anna
@Dimitre: +1 for divide by xs:duration (I was extracting each component, so I've deleted the answer). But I keep thinking if **time zone** is defined for *nix epoch.
Alejandro