Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 6th, 2009, 02:08 AM
Registered User
 
Join Date: Mar 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default converting date format from utc time in seconds to GMT

Hi All,


I have a situation, where I have to convert date:1224850501 which is UTC( seconds from 1970) to GMT:2008-10-24T12:15:01.

If some one knowa how to conver the date plz replay me.

Thanks In Advance
 
Old March 6th, 2009, 02:50 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Please show your input xml, code and needed output.
__________________
Rummy
 
Old March 6th, 2009, 02:59 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Try current-dateTime() function.
__________________
Rummy
 
Old March 6th, 2009, 05:07 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT 2.0,

($in * xs:dayTimeDuration('PT1S')) + xs:dateTime('1970-01-01T00:00:00')

where $in is the input, as an integer.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old March 9th, 2009, 08:38 AM
Registered User
 
Join Date: Mar 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Thanks Rummy and Kay.

Plz find the input xml and out put xml.

input file:

<dm_document>
<r_creation_date dmfttype="dmdate">1236610744</context>
</dm_document>

output file

<dm_document> <r_creation_date dmfttype="dmdate">2009-03-09T14:59:04</r_creation_date>
</dm_document>





Basically the value of the r_creation_time in the input value is in seconds from 1970.
Awaiting for your(Rummy and Kay) reply.
Thanks
--Murali
 
Old March 9th, 2009, 08:46 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

What part of my previous response didn't you understand?
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old March 10th, 2009, 12:41 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Mike has already replied for your question.

Try this:

Code:
 
<xsl:template match="dm_document">
<xsl:apply-templates select="r_creation_date"></xsl:apply-templates>
</xsl:template>

<xsl:template match="r_creation_date">
<xsl:variable name="in" select="."></xsl:variable>
<xsl:value-of select="($in * xs:dayTimeDuration('PT1S')) + xs:dateTime('1970-01-01T00:00:00')"></xsl:value-of>
</xsl:template>

__________________
Rummy
 
Old March 10th, 2009, 07:25 AM
Registered User
 
Join Date: Mar 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Rummy,

Thanks for your help.
It did worked from the xslt editor(Altova). I am using this template in java.
Java uses 1.0 xslt version, looks to be the api is not supported in java.
I have got the following error.

Can you help me how to get out of this situation?

ERROR: 'The first argument to the non-static Java function 'dayTimeDuration' is not a valid object reference.'
FATAL ERROR: 'Could not compile stylesheet'
Exception in thread "main" javax.xml.transform.TransformerConfigurationExcept ion: Could not compile stylesheet
at com.sun.org.apache.xalan.internal.xsltc.trax.Trans formerFactoryImpl.newTemplates(TransformerFactoryI mpl.java:829)
at com.sun.org.apache.xalan.internal.xsltc.trax.Trans formerFactoryImpl.newTransformer(TransformerFactor yImpl.java:623)
at com.emc.documentum.ess.SimpleJaxp1.main(SimpleJaxp 1.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main (AppMain.java:90)
Process finished with exit code 1

Many thanks Rummy.
 
Old March 10th, 2009, 07:56 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

Use Saxon 9B as it is xslt 2.0 compliant and free, its also written in java so you should have no problems





Similar Threads
Thread Thread Starter Forum Replies Last Post
Local Date and Time to UTC? dbayona SQL Server 2005 3 July 24th, 2007 10:12 PM
Converting date to yy.mm.dd format using CONVERT Jinn SQL Server 2000 6 October 14th, 2006 06:44 PM
Converting a date format to dd-Mon-yyyy cole SQL Server 2000 4 January 25th, 2006 12:10 AM
Converting Seconds into Nano seconds and viceversa chandu80 General .NET 0 June 4th, 2005 01:18 AM
time (UTC v local and NOW()) m3rajk PHP Databases 2 August 18th, 2003 12:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.