Print local time
Wednesday, 27 April 2016 · 3 messages
MC
Mike Cobo27 Apr 2016 15:26 #
Hi all
I want to print the current date and time on a HTML page using XQuery's format-dateTime function. The problem is that I always get the GMT time which currently is 2 hours behind of Central Europe Time. This is what my code looks like: <p>Stand vom {format-dateTime(current-dateTime(), '[D01].[M01].[Y0001] [H01]:[m01]:[s01]', 'de')} Uhr</p>
And this is what I get when local time is 15:21:34:
Stand vom 27.04.2016 13:21:34 Uhr
Is it possible to get the local time using format-dateTime?
Thanks for any help!
Mike
CG
Christian Grün27 Apr 2016 15:43 #
Hi Mike,
Quoted text · Mike Cobo · 1 line
> Stand vom 27.04.2016 13:21:34 Uhr
That’s interesting; the same query here in Konstanz/Germany gives me:
<p>Stand vom 27.04.2016
15:38:53 Uhr</p>Maybe this is due to your server settings?
You can enforce the time adjustment as follows:
adjust-dateTime-to-timezone(
current-dateTime(),
xs:dayTimeDuration('PT2H')
)It is true that the XQuery 3.1 F&O spec allows you to specify a place [1]. This hasn’t been implemented yet…
Hope this helps,
Christian
[1] https://www.w3.org/TR/xpath-functions-31/#rules-for-datetime-formatting
MC
Mike Cobo27 Apr 2016 16:04 #
Hi Christian
You were right: as I'm running BaseX on a VM I checked the time on the VM's server and this is the time I get when runing the XQuery.Your workaround solution with the adjust-dateTime-to-timezone function also worked as expected. Thnx!
Best regardsMike
From: Christian Grün <christian.gruen at gmail.com>
To: Mike Cobo <mikecobo at yahoo.com>
Cc: "basex-talk at mailman.uni-konstanz.de" <basex-talk at mailman.uni-konstanz.de> Sent: Wednesday, April 27, 2016 3:43 PM
Subject: Re: [basex-talk] Print local time
Hi Mike,
Quoted text · Christian Grün · 1 line
> Stand vom 27.04.2016 13:21:34 Uhr
That’s interesting; the same query here in Konstanz/Germany gives me:
<p>Stand vom 27.04.2016
15:38:53 Uhr</p>Maybe this is due to your server settings?
You can enforce the time adjustment as follows:
adjust-dateTime-to-timezone(
current-dateTime(),
xs:dayTimeDuration('PT2H')
)It is true that the XQuery 3.1 F&O spec allows you to specify a place [1]. This hasn’t been implemented yet…
Hope this helps,
Christian
[1] https://www.w3.org/TR/xpath-functions-31/#rules-for-datetime-formatting
Written for BaseX 8.4. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery