如果你要的XQuery 3.0訪問,你可以採取的format-dateTime($date, $picture)
優勢:
let $date := xs:dateTime("2004-05-02T00:00:00+01:00")
return format-dateTime($date, "[D,2][M,2][Y,4]")
如果你還沒有(僅XQuery 1.0),你仍然可以使用更多的語義版本。因爲它也沒有format-number(...)
功能,我使用了一些準備功能從functx:
declare namespace functx = "http://www.functx.com";
declare function functx:pad-integer-to-length
($integerToPad as xs:anyAtomicType? ,
$length as xs:integer) as xs:string {
if ($length < string-length(string($integerToPad)))
then error(xs:QName('functx:Integer_Longer_Than_Length'))
else concat
(functx:repeat-string(
'0',$length - string-length(string($integerToPad))),
string($integerToPad))
} ;
declare function functx:repeat-string
($stringToRepeat as xs:string? ,
$count as xs:integer) as xs:string {
string-join((for $i in 1 to $count return $stringToRepeat),
'')
} ;
let $date := xs:dateTime("2004-05-02T00:00:00+01:00")
let $date := xs:date($date)
return string-join((
functx:pad-integer-to-length(day-from-date($date), 2),
functx:pad-integer-to-length(month-from-date($date), 2),
functx:pad-integer-to-length(year-from-date($date), 4)
))
決定你自己,如果你喜歡比較笨重,但語義版本或簡單的字符串處理。請注意,根據您選擇的時區,時區可能會導致不同的結果。