declare function xf:current-formatted-dateTime()
as xs:string {
let $currentDate := fn:current-date()
let $currentTime := fn:current-time() (: no seconds-from-dateTime() :-( :)
let $year := fn:year-from-date($currentDate)
let $month := fn:month-from-date($currentDate)
let $day := fn:day-from-date($currentDate)
let $hours := fn:hours-from-time($currentTime)
let $minutes := fn:minutes-from-time($currentTime)
let $seconds := fn:seconds-from-time($currentTime)
let $monthZeroPadded :=
if($month < 10) then xs:string(concat('0', $month))
else xs:string($month)
let $dayZeroPadded :=
if($day < 10) then xs:string(concat('0', $day))
else xs:string($day)
let $hoursZeroPadded :=
if($hours < 10) then xs:string(concat('0', $hours))
else xs:string($hours)
let $minutesZeroPadded :=
if($minutes < 10) then xs:string(concat('0', $minutes))
else xs:string($minutes)
let $secondsNoMS := xs:integer(fn:substring-before(xs:string($seconds), '.'))
let $secondsNoMSZeroPadded :=
if($secondsNoMS < 10) then xs:string(concat('0', $secondsNoMS))
else xs:string($secondsNoMS)
return concat($year, '-', $monthZeroPadded, '-', $dayZeroPadded, ' ', $hoursZeroPadded, ':', $minutesZeroPadded, ':', $secondsNoMSZeroPadded)
};
It can be placed and used this way:
Produces this kind of output: 2013-07-07 17:38:05
No hay comentarios:
Publicar un comentario