Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 6th, 2008, 01:16 PM
Authorized User
Points: 60, Level: 1
Points: 60, Level: 1 Points: 60, Level: 1 Points: 60, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2008
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old May 6th, 2008, 01:48 PM
Authorized User
Points: 340, Level: 6
Points: 340, Level: 6 Points: 340, Level: 6 Points: 340, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2008
Location: , OH, USA.
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!
Reply With Quote
  #3 (permalink)  
Old May 6th, 2008, 04:30 PM
Authorized User
Points: 60, Level: 1
Points: 60, Level: 1 Points: 60, Level: 1 Points: 60, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2008
Location: , , .
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

Reply With Quote
  #4 (permalink)  
Old May 7th, 2008, 05:24 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
Reply With Quote
  #5 (permalink)  
Old May 7th, 2008, 05:27 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
Reply With Quote
  #6 (permalink)  
Old May 7th, 2008, 05:47 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #7 (permalink)  
Old May 7th, 2008, 07:43 AM
Authorized User
Points: 340, Level: 6
Points: 340, Level: 6 Points: 340, Level: 6 Points: 340, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2008
Location: , OH, USA.
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>

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:31 PM.


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