Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > timestamp

Reply
Thread Tools

timestamp

 
 
Thomas Mann
Guest
Posts: n/a
 
      10-13-2004
Hello,

using XSLT 2.0 I can get a timestamp with the following line:
<xsl:value-of select="current-dateTime()"/>
How can I format the date and the time ? For example I do not want the
milliseconds to be shown.

BR
Thomas


 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      10-14-2004


Thomas Mann wrote:


> using XSLT 2.0 I can get a timestamp with the following line:
> <xsl:value-of select="current-dateTime()"/>
> How can I format the date and the time ? For example I do not want the
> milliseconds to be shown.


Well, check the XPath 2.0 function reference, it shows a function
http://www.w3.org/TR/xslt20/#function-format-dateTime
format-dateTime that should allow you to format the result returned by
current-dateTime().
Here is an example, the second argument to format-dateTime is a string
with a so called picture which in my view would better be called
formatting pattern:

<xsl:template match="/">
<xsl:variable name="now" select="current-dateTime()" />
<root>
<result-unformatted><xsl:value-of select="$now" /></result-unformatted>
<result-formatted picture="[Y]-[M]-[D]">
<xsl:value-of select="format-dateTime($now, '[Y]-[M]-[D]')" />
</result-formatted>
<result-formatted picture="[Y]-[M]-[D]T[H]:[m]:[s]">
<xsl:value-of select="format-dateTime($now,
'[Y]-[M]-[D]T[H]:[m]:[s]')" />
</result-formatted>
</root>
</xsl:template>

An example output here on my machine with Saxon 8.1.1 is

<?xml version="1.0" encoding="UTF-8"?>
<root>
<result-unformatted>2004-10-14T12:27:39.921+02:00</result-unformatted>
<result-formatted picture="[Y]-[M]-[D]">2004-10-14</result-formatted>
<result-formatted
picture="[Y]-[M]-[D]T[H]:[m]:[s]">2004-10-14T12:27:39</result-formatted>
</root>


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert to NTP Timestamp Manzoorul Hassan Perl 1 03-11-2005 05:37 PM
filter ICMP timestamp request on Cisco router or PIX szehun@gmail.com Cisco 1 12-16-2004 09:44 AM
filter ICMP timestamp request on Cisco router or PIX szehun@gmail.com Cisco 0 12-16-2004 08:55 AM
PIX logging without timestamp Ste Cisco 2 09-04-2004 01:08 AM
log timestamp format Bill F Cisco 3 07-24-2003 05:40 AM



Advertisments