XML technologies / XSLT / Introduction to XSLT 2.0 / XSLT and XPath – round three / Date, duration and timestamp values / Timestamp value with fn:current-dateTime()
(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, Chapter 3.)
A timestamp value is a combination of a date value and a time of day. Its string representation is 2007-09-03T20:06:35.562+01:00 or similar.
<xsl:variable name="jetzt" select="fn:current-dateTime()"/>
Code example: kap03/3.05/date.xsl (excerpt).
The function for formatting it is format-dateTime():
<p>Heute ist der <xsl:value-of select="format-dateTime($jetzt,'[D01].[M01].[Y0001], [H10]:[m01] Uhr')"/>.</p>
Code example: kap03/3.05/date.xsl (excerpt).
This produces the output: »Heute ist der 01.07.2007, 20:18 Uhr.«
To omit leading zeros in the output, simply leave them out of the formatting string:
<p>Heute ist der <xsl:value-of select="format-dateTime($jetzt,'[D1].[M1].[Y0001], [H10]:[m01] Uhr')"/>.</p>
Code example: kap03/3.05/date.xsl (excerpt).
This produces the output: »Heute ist der 1.7.2007, 20:18 Uhr.«
Copyright © Galileo Press, Bonn 2008
You may print the online version for your private use.
Otherwise, this chapter from "XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch" is subject to the same terms as the printed edition: the work and all its parts are protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn