Name
[2.0] current-time()
Returns an xs:time object set to
the current time.
Syntax
xs:timecurrent-time()
Inputs
None.
Output
An xs:time value set to
the current 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-time()
function returns the same value throughout the
processing of the stylesheet. If you call current-time() 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 2, “Accessors.”
Example
Here is a stylesheet that displays the current time. It uses
the current-time(),
format-time(), and implicit-timezone()
functions:
<?xml version="1.0"?> <!-- current-time.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 time is </xsl:text> <xsl:value-of select="format-time(current-time(), '[h]:[m01] [Pn]')"/> <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-time(current-time())"/> </xsl:template> </xsl:stylesheet>
The exciting results from this stylesheet look like this:
The current time is 6:49 a.m. The implicit ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access