Display current time +1h ?
This is an open discussion with 3 replies, filed under XSLT.
Search
You can use the EXSLT library to manipulate dates: dates and times
First import the EXSLT date-time namespace to your stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date">
Then something like:
<xsl:value-of select="date:add($today, 'P1D')"/>
The add
function accepts a date in ISO format (which the $today
parameter provides), plus a “duration”. Durations are expressed in a specific format. In this instance is is P
followed by the duration, in this case one day 1D
.
This should output:
2010-01-05
Oh! You wanted one hour, not one day. In this case add the time to the mix too:
<xsl:value-of select="date:add(concat($today,'T',$current-time,':00'), 'PT1H')"/>
Concatenate the date and time together to form an ISO-format date in the form:
YYYY-MM-DDTHH:MM:SS
Then add T
to the duration format (signifying you’re specifying time) and use H
for hours.
Thanks Nick for the info… will give it a try
Create an account or sign in to comment.
Hi,
I used current-time to display the local time. Because of a move to a different time zone I need to add an extra hour to the output. Can’t remember how his can be done…
Thanks!