Is there any way in XQuery to get the current time in milliseconds since some Epoch?

与世无争的帅哥 提交于 2019-12-20 10:37:33

问题


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?


回答1:


(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.




回答2:


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") }



回答3:


Additional tricks on Aditya's answer for OSB 11g.

There has an annoying bug on XQ Editors that will change div and operator into a , (comma).

Just put a conversion function in front of that code. such as xs:long, xs:string

ex.

{ xs:long((fn:current-dateTime() - xs:dateTime("1970-01-01T00:00:00-00:00")) div xdt:dayTimeDuration("PT0.001S")) }


来源:https://stackoverflow.com/questions/7482347/is-there-any-way-in-xquery-to-get-the-current-time-in-milliseconds-since-some-ep

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!