1

I am unable to get any in-built method for retrieving milli-second part of the given date-time.

Method current-dateTime() returns the full date & time along with milli-seconds, but I am looking for in-built one just to return millisecond.

In-built methods are available for hours, minutes and for seconds but not for milliseconds.

Please note, I do not wish to get the unix-timestamp

Community
  • 1
  • 1
Atur
  • 1,712
  • 6
  • 32
  • 42

2 Answers2

2

As I found no default method, I used following approach to get milliseconds

  let $sec := fn:seconds-from-dateTime($currentTime) 
  let $splitSeconds := fn:tokenize(fn:string($sec), '\.')
  let $seconds := $splitSeconds[1]
  let $milliSeconds := $splitSeconds[2]
Atur
  • 1,712
  • 6
  • 32
  • 42
  • 1
    Adam's approach has the benefit of handling time zones. To handle this possibility, you could tokenize `$milliSeconds` on `[-+]`. – Joe Wicentowski May 29 '14 at 11:16
2

Indeed, such a function for getting just the milliseconds appears to be missing from XQuery, however this is most likely because if you read the spec, then seconds are modeled as a decimal rather than as two separate seconds and milliseconds components.

Another alternative to your answer is to use a regular expression:

replace(string($currentTime), ".*\.([0-9]*)[+\-].*", "$1")
adamretter
  • 3,885
  • 2
  • 23
  • 43