如何使用 XPath 获取两个日期之间的秒数 [英] How to get number of secondes between two dates with XPath

查看:42
本文介绍了如何使用 XPath 获取两个日期之间的秒数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 WSO2 ESB,我想知道如何获得日期 A 和 B 之间的秒表.基本上,我想计算系统时间和下午 12 点之间的时间.你有什么主意吗 ?我找到了如何仅使用 Xpath 获取天数但没有任何秒数.我受 Xpath 限制,因为我不能使用 Java 脚本.

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.

谢谢.

推荐答案

基本是把两者都变成合适的 xs:dateTime 对象,然后计算差异.这会给你一个dayTimeDuration.将其除以 1 秒的 dayTimeDuration,您就得到了以秒为单位的差异.示例:

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')"/>

请记住,您需要在 ESB/EI 上为此启用 xpath 2.0.您可以通过取消注释 [WSO2CARBON_HOM]/repository/conf/synapse.properties 文件中的以下行来实现此目的.

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

还请记住,一旦您完成了该操作,将来自突触命名空间(如 get-property)的函数与普通 xpath 函数相结合的 xpath 表达式将需要使用代码示例中的前缀.

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.

这篇关于如何使用 XPath 获取两个日期之间的秒数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆