Subject: [xsl] The UNIX epoch, or time since Jan 01, 1970 From: Florent Georges <lists@xxxxxxxxxxxx> Date: Mon, 21 May 2012 17:06:49 +0100 (BST) |
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/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Apology, ihe onwuka | Thread | Re: [xsl] The UNIX epoch, or time s, G. Ken Holman |
Re: [xsl] Finding the closest prece, Syd Bauman | Date | Re: [xsl] The UNIX epoch, or time s, G. Ken Holman |
Month |