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 May 6th, 2008, 01:16 PM
Authorized User
 
Join Date: May 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default get the current system data and time

Hi,

Is there any function to get the current system date and time in long format (20080303 hh:mm:ss:mi EST).

Thanks,
Arun

 
Old May 6th, 2008, 01:48 PM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default

It is my understanding that you can make use of the XPath function 'current-dateTime()' to retrieve the system time.

This would provide you with the current system time in the xs:dateTime type.

You could then make use of the format-dateTime() function to restructure the time in the format that you require. You can basically customize the way you want to output the current time.

A very simple style sheet with no input document.

Code:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />

<xsl:template match="/">
<html>
<body>
<xsl:value-of select="format-dateTime(current-dateTime(), '[Y,4][D,2][M,2] [H]:[m]:[s] [Z]')" />
</body>
</html>        
</xsl:template>

</xsl:stylesheet>
This stylesheet will output the following:
Code:
<html>
  <body>20080605 14:45:04 -04:00</body>
</html>
Good luck!
 
Old May 6th, 2008, 04:30 PM
Authorized User
 
Join Date: May 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

The below output looks good but it is missing the 'milliseconds'in the time format .Is there any function to get the time in long format including milli seconds

"20080605 14:45:04:59 -04:00"

Thanks,
Arun

 
Old May 7th, 2008, 05:24 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

There's a function current-dateTime() in XPath 2.0, and a function format-dateTime() in XSLT 2.0 that will format it the way you want - except for the EST bit (which might not work reliably because the function doesn't necessarily know that you're in the United States in winter; all it knows is the timezone offset -05:00)

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 7th, 2008, 05:27 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The precision of the date/time is implementation-defined, though all implementations are supposed to provide at least 3 digits (millisecond precision).

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 7th, 2008, 05:47 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
quote:Originally posted by mhkay
 There's a function current-dateTime() in XPath 2.0, and a function format-dateTime() in XSLT 2.0 that will format it the way you want - except for the EST bit (which might not work reliably because the function doesn't necessarily know that you're in the United States in winter; all it knows is the timezone offset -05:00)

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Winter in the US? I thought he was asking for Eastern Summer Time in Australia :)

--

Joe (Microsoft MVP - XML)
 
Old May 7th, 2008, 07:43 AM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default

Quote:
quote:Originally posted by arunprasadlv
 Hi,

The below output looks good but it is missing the 'milliseconds'in the time format .Is there any function to get the time in long format including milli seconds

"20080605 14:45:04:59 -04:00"

Thanks,
Arun

With milliseconds

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" />

<xsl:template match="/">
<html>
<body>
<xsl:value-of select="format-dateTime(current-dateTime(), '[Y,4][D,2][M,2] [H]:[m]:[s]:[f01] [Z]')" />
</body>
</html>
</xsl:template>

</xsl:stylesheet>






Similar Threads
Thread Thread Starter Forum Replies Last Post
Current Date and Time in XSLT devMc XSLT 6 October 21st, 2007 04:49 AM
Insert System date and System Time -Form _TextBox cnkumar74 VB How-To 14 February 14th, 2007 10:52 AM
Check to See if Current Time is between hours mvollmer Classic ASP Professional 5 July 28th, 2004 07:49 PM
sql - comparing current time suzila VB.NET 2002/2003 Basics 7 May 14th, 2004 12:05 AM





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