timestamp

T

Thomas Mann

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
 
M

Martin Honnen

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]:">
<xsl:value-of select="format-dateTime($now,
'[Y]-[M]-[D]T[H]:[m]:')" />
</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]:">2004-10-14T12:27:39</result-formatted>
</root>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top