How to get number of secondes between two dates with XPath [duplicate]

倾然丶 夕夏残阳落幕 提交于 2020-07-22 21:41:59

问题


I am working with WSO2 ESB and i would like to know how can i get secondes betwenn date A and B. Basically, i would like to calcul time between system time and 12.00pm. Do you have any idea ? I found how to do get number of days but nothing for secondes with Xpath only. I am restricted with Xpath because i can't use a Java script.

Thank you.


回答1:


The basic is to turn both into proper xs:dateTime objects, then calculate the difference. This will give you a dayTimeDuration. Divide this by the dayTimeDuration of 1 second and you have your difference in seconds. Example:

<property xmlns:xs="http://www.w3.org/2001/XMLSchema" name="now" 
expression="concat(get-property('SYSTEM_DATE', 'yyyy-MM-dd'),'T',get-property('SYSTEM_DATE', 'HH:mm:ss')) "/>
<property xmlns:xs="http://www.w3.org/2001/XMLSchema" name="12pm" 
expression="concat(get-property('SYSTEM_DATE', 'yyyy-MM-dd'),'T12:00:00')"/>


<property xmlns:xs="http://www.w3.org/2001/XMLSchema" name="diff" 
expression="xs:dayTimeDuration(xs:dateTime(syn:get-property('now'))-xs:dateTime(syn:get-property('12pm'))) div xs:dayTimeDuration('PT1S')"/>

Keep in mind you need to enable xpath 2.0 for this on the ESB/EI. You can do this by uncommenting the following line in your [WSO2CARBON_HOM]/repository/conf/synapse.properties file.

#synapse.xpath.dom.failover.enabled=true

Also keep in mind that once you have done that, xpath expression where you combine functions from synapse namespace (like get-property) with normal xpath functions will require the use of a prefix like in the code example.



来源:https://stackoverflow.com/questions/55339702/how-to-get-number-of-secondes-between-two-dates-with-xpath

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