The following examples covers DateTime , Time Zone and dateTime formatting
to learn more about ddtek:format-dateTime see Stylus XQuery user's guide
declare option ddtek:serialize "method=text";
declare function local:print-examples($examples)
{
fn:string-join(
for $example in $examples return xs:string($example)
," "
)
};
declare function local:shift-dateTime-to-time-zone($dt as xs:dateTime, $offset as xs:dayTimeDuration) as xs:dateTime
{
let $utc := fn:adjust-dateTime-to-timezone($dt , xs:dayTimeDuration('P0D'))
let $target := fn:adjust-dateTime-to-timezone($utc , $offset)
return $target
};
declare variable $now := fn:current-dateTime();
declare variable $local-time-zone := fn:timezone-from-dateTime($now);
declare variable $examples :=
(
fn:concat("current date time ISO 8601 -> ", $now)
,fn:concat("UTC date time -> ", fn:adjust-dateTime-to-timezone($now, xs:dayTimeDuration('P0D')))
,fn:concat("time offset from local to MYT(+8) -> ", local:shift-dateTime-to-time-zone($now, xs:dayTimeDuration('PT8H')))
,fn:concat("local time zone -> ", fn:timezone-from-dateTime($now))
,fn:concat("format date US as mm dd yyyy hh:mm:ss -> " ,ddtek:format-dateTime($now, "[M01]-[D01]-[Y0001] [H01]:[m01]:[s01]"))
,fn:concat("format date EU as dd mm yyyy hh:mm:ss -> " ,ddtek:format-dateTime($now, "[D01]-[M01]-[Y0001] [H01]:[m01]:[s01]"))
);
local:print-examples($examples)
XQuery Output
current date time ISO 8601 -> 2024-10-30T14:33:56.357-04:00
UTC date time -> 2024-10-30T18:33:56.357Z
time offset from local to MYT -> 2024-10-31T02:33:56.357+08:00
local time zone -> -PT4H
format date US as mm dd yyyy hh:mm:ss -> 10-30-2024 14:33:56
format date EU as dd mm yyyy hh:mm:ss -> 30-10-2024 14:33:56
Comments
0 comments
Please sign in to leave a comment.