[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: The UNIX epoch, or time since Jan 01, 1970

Subject: Re: The UNIX epoch, or time since Jan 01, 1970
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 21 May 2012 12:28:04 -0400
Re:  The UNIX epoch
At 2012-05-21 17:06 +0100, Florent Georges wrote:
  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:

Remember you can do arithmetic with durations. I think this is even simpler:


T:\ftemp>xslt2 florent.xsl florent.xsl
<?xml version="1.0" encoding="UTF-8"?>1337617644.811
T:\ftemp>xslt2 florent.xsl florent.xsl
<?xml version="1.0" encoding="UTF-8"?>1337617649.455
T:\ftemp>type florent.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"
     xmlns:my="urn:X-florent"
  version="2.0">

<xsl:template match="/">
  <xsl:value-of select="my:current-timestamp()"/>
</xsl:template>

<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"/>
       <!-- number of seconds -->
       <xsl:sequence select="string($diff div xs:dayTimeDuration('PT1S'))"/>
    </xsl:function>

</xsl:stylesheet>
T:\ftemp>

I hope this helps.

. . . . . . . . Ken

--
Public XSLT, XSL-FO, UBL and code list classes in Europe -- Oct 2012
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/s/
G. Ken Holman                   mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.