[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] The UNIX epoch, or time since Jan 01, 1970
Hi, As part of sending an OAuth request to connect to Twitter, I have to get a timestamp, as the number of seconds elapsed from Jan 01, 1970 (AKA the UNIX epoch). The simplest solution I could come with is the following: <xsl:function name="my:current-timestamp" as="xs:string"> <!-- the UNIX epoch --> <xsl:variable name="epoch" select="xs:dateTime('1970-01-01T00:00:00Z')"/> <!-- time since then --> <xsl:variable name="diff" select="current-dateTime() - $epoch"/> <!-- all components, in seconds... --> <xsl:variable name="days" select="days-from-duration($diff) * (24*60*60)"/> <xsl:variable name="hours" select="hours-from-duration($diff) * (60*60)"/> <xsl:variable name="mins" select="minutes-from-duration($diff) * 60"/> <xsl:variable name="secs" select="floor(seconds-from-duration($diff))"/> <!-- sum each of them --> <xsl:sequence select="xs:string($days + $hours + $mins + $secs)"/> </xsl:function> It looks to me like this is rather complex to get such a timestamp. Did I miss something? Is there a way to simplify this? If not, and because this is a kind of value (unfortunately) still used in recents API, it would probably be interesting to add a new specifier for it in the picture string format for fn:format-dateTime(). Regards, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|