XQuery
offers various date/time
functions like current-dateTime()
, however I can't seem to find one which gives me the time in milliseconds since Epoch. Functions to extract hours, minutes and seconds seem to exist too individually.
What is the right way to get the Epoch time (i.e. unix time or similar) in XQuery
?
To get the current time in milliseconds, you just need to convert the output of Sys. time to numeric, and multiply by 1000.
You need to multiply it by 1000 before adding a millisecond to it.
Datetime Unix timestamp contains milliseconds.
Convert from human-readable date to epochlong epoch = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/1970 01:00:00").getTime() / 1000; Timestamp in seconds, remove '/1000' for milliseconds.
thank you for the tips. I modify the code for Oracle Service Bus 11g (OSB 11g) Xpath editor in case someone else needs it
{ (fn:current-dateTime() - xs:dateTime("1970-01-01T00:00:00-00:00")) div xdt:dayTimeDuration("PT0.001S") }
(current-dateTime() - xs:dateTime("1970-01-01T00:00:00-00:00")) div xs:dayTimeDuration('PT0.001S')
returns the number of seconds as a duration, and then divides by 1 millisecond to get the number of milliseconds as a number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With