[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: difference between an integer and current-dateTime
I hope this helps.
. . . . . Ken ~/t $ xslt2 unixtime.xsl unixtime.xsl Given: 1585039138 Then: 2020-03-24T08:38:58 Current: 1585296916.838 Current dateTime: 2020-03-27T08:15:16.838-04:00 Difference: 257778.838 Half-way: 128889.419 Half-way dateTime: 2020-03-25T20:27:07 ~/t $ cat unixtime.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:output method="text"/> <xsl:template match="/"> <xsl:variable name="oldTime" select="1585039138"/> <xsl:variable name="epoch" select="xs:dateTime('1970-01-01T00:00:00')"/> <xsl:variable name="now" select="xs:duration(current-dateTime()-$epoch) div xs:dayTimeDuration('PT1S')"/> <xsl:value-of select="'Given:',$oldTime,'
'"/> <xsl:value-of select="'Then:',format-dateTime( $epoch + xs:dayTimeDuration( concat('PT',$oldTime,'S') ), '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]'),'
' "/> <xsl:value-of select="'Current:',$now,'
'"/> <xsl:value-of select="'Current dateTime:',current-dateTime(),'
'"/> <xsl:value-of select="'Difference:', $now - $oldTime,'
'"/> <xsl:value-of select="'Half-way:', ($now - $oldTime) div 2,'
'"/> <xsl:value-of select="'Half-way dateTime:', format-dateTime( $epoch + xs:dayTimeDuration( concat('PT',$oldTime + ( ($now - $oldTime) div 2 ),'S') ), '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]'),'
'"/> </xsl:template> </xsl:stylesheet> ~/t $ At 2020-03-27 10:34 +0000, Mukul Gandhi gandhi.mukul@xxxxxxxxx wrote: Hi all, B B I've got a number 1585039138 for example (which is number of seconds since epoch 1970-01-01T00:00:00Z UTC). I wish to find the duration (in minutes or seconds) between previous number and current-dateTime(). I wish to do this with XSLT (2/3 both are fine with me, preferably non schema aware). I expect this difference to be always positive, since the number will change depending on what moment (at any moment, I wish to find this difference) it is calculated. How can I do that? -- Contact info, blog, articles, etc. http://www.CraneSoftwrights.com/s/ | Check our site for free XML, XSLT, XSL-FO and UBL developer resources | Streaming hands-on XSLT/XPath 2 training class @ US$45 (5 hours free) | Essays (UBL, XML, etc.) http://www.linkedin.com/today/author/gkholman |
|
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
|