【问题标题】:Xquery returning string instead of formatted dateXquery 返回字符串而不是格式化日期
【发布时间】:2013-11-21 01:19:49
【问题描述】:

我在 XML 存储库 Xhive 上运行一个简单的 Xquery,但在返回某个日期的值时遇到了问题:

Xquery:

for $x in document('')[matches(xhive:metadata(., "docato-name"),"THOCEO")][xhive:metadata(., "docato-type") = 'XML_RESOURCE_TYPE']
return
<file>
      <filename>{xhive:metadata($x, "docato-name")}</filename>
      <validated>{xhive:metadata($x,"Last Modified")}</validated>
</file>

结果:

<result>
    <file>
        <filename>THOCEO</filename>
        <validated>1375875821721</validated>
    </file>
</result>

我希望将“上次修改”日期返回为存储库中显示的格式化日期:“2013-08-07 12:43:41”而不是上述字符串(“1375875821721”)

我尝试将查询修改为“{xs:date(xhive:metadata($x,"Last Modified"))}”,但失败并出现错误:

query:8:19:XQUERY_ERROR_VALUE: casting error, cannot cast '1375875821721' from xdt:untypedAtomic to {http://www.w3.org/2001/XMLSchema}date (FORG0001: Invalid value for cast/constructor.)

任何将“上次修改”日期作为格式化日期返回的帮助将不胜感激!

谢谢!

【问题讨论】:

    标签: xml date datetime xquery documentum


    【解决方案1】:

    是的,我会说使用 xhive:last-modified(...) 是最简单的方法,但如果你真的想使用时间戳,那么这里是我过去使用过的东西:

    declare function local:timestamp-to-dateTime($v) as xs:dateTime { 
      xs:dateTime("1970-01-01T00:00:00-00:00") + xs:dayTimeDuration(concat("PT", $v idiv 1000, "S"))
    };
    
    local:timestamp-to-dateTime(number("1375875821721"))
    

    【讨论】:

    • 非常感谢那个 Ewout,成功了!恐怕我不能给你一个 +1 的原因,因为我的声誉是 1,但如果我达到 15,我会尽量记住!
    【解决方案2】:

    我不确定该数字代表什么或如何解析它,但您可以尝试xhive:last-modified(),它返回xs:dateTime:

    <validated>{ xhive:last-modified(fn:document-uri($x)) }</validated>
    

    【讨论】:

    • 嗨,当我尝试运行您在上面详述的 xhive:last-modified 函数时,我收到以下错误:query:8:20:XQUERY_UNKNOWN_FUNCTION: {http://www.x-hive.com/2001/08/xquery-functions}last-modified/1 (XPST0017: It is a static error if the expanded QName and number of arguments in a function call do not match the name and arity of a function signature in the static context.)
    • @user2083508 你确定你没有将空传递给函数吗?你能隔离一个对xhive:last-modified()的调用吗?
    猜你喜欢
    • 2016-06-25
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 2017-06-27
    • 1970-01-01
    • 2018-12-04
    相关资源
    最近更新 更多