Name
[2.0] current-dateTime()
Returns the current date and time as an xs:dateTime
value.
Syntax
xs:dateTimecurrent-dateTime(
)
Inputs
None.
Output
An xs:dateTime
value set
to the current date and time on the system. The returned value is
set to the default timezone. (You can get the details of the
default timezone with the context function implicit-timezone()
). The
current-dateTime()
function
returns the same value throughout the processing of the
stylesheet. If you call current-dateTime()
a dozen times
throughout your stylesheet, the function returns the same value
each time.
Defined in
XQuery 1.0 and XPath 2.0 Functions and Operators section 16, “Context Functions.”
Example
Here is a stylesheet that displays the current date and
time. It uses the current-dateTime()
, format-dateTime()
and implicit-timezone()
functions.
<?xml version="1.0"?> <!-- current-datetime.xsl --> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>The current date and time is </xsl:text> <xsl:value-of select="format-dateTime(current-dateTime(), '[h]:[m01] [Pn] on [FNn], the [D1o] of [MNn], [Y]')"/> <xsl:text>

The implicit timezone for the </xsl:text> <xsl:text>current context is: </xsl:text> <xsl:value-of select="implicit-timezone()"/> <xsl:text>

The timezone extracted from the </xsl:text> <xsl:text>current date and time is: </xsl:text> <xsl:value-of select="timezone-from-dateTime(current-dateTime())"/> ...
Get XSLT, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.