admin管理员组文章数量:1430020
I am currently having some challenge in converting String
data type to Date
type. I used the MarkLogic JavaScript function xdmp.parseDateTime
, but I am always getting the error below:
Scenario: Convert "2013-04-21" (string) to 2013-04-21 (date type)
Code:
let targetDateString = "2013-04-21";
let targetDate = new Date();
targetDate = xdmp.parseDateTime("[Y0001]-[M01]-[D01]",
xs.date(targetDate));
Error Info:
XDMP-ARGTYPE: xdmp.parseDateTime("[Y0001]-[M01]-[D01]", xs.date("2013-04-21")) -- arg2 is not of type String
Am I using the right MarkLogic function, supplying the right parameters to it? Or is there a better way to do it?
And how do I cast a date back to a string data type?
I am currently having some challenge in converting String
data type to Date
type. I used the MarkLogic JavaScript function xdmp.parseDateTime
, but I am always getting the error below:
Scenario: Convert "2013-04-21" (string) to 2013-04-21 (date type)
Code:
let targetDateString = "2013-04-21";
let targetDate = new Date();
targetDate = xdmp.parseDateTime("[Y0001]-[M01]-[D01]",
xs.date(targetDate));
Error Info:
XDMP-ARGTYPE: xdmp.parseDateTime("[Y0001]-[M01]-[D01]", xs.date("2013-04-21")) -- arg2 is not of type String
Am I using the right MarkLogic function, supplying the right parameters to it? Or is there a better way to do it?
And how do I cast a date back to a string data type?
Share Improve this question edited Jul 22, 2018 at 23:57 Mads Hansen 67k12 gold badges116 silver badges152 bronze badges asked May 3, 2018 at 8:01 RyanRyan 17510 bronze badges 02 Answers
Reset to default 5xs.date("2013-04-21")
is the xquery date constructor (ported to JS), taking a string and returning an xs:date. xs.dateTime("2013-04-21T00:00:00")
would get you an xs:dateTime.
xdmp.parseDateTime
can turn a string to xs:dateTime from more formats, the second term is a string: xdmp.parseDateTime("[Y0001]-[M01]-[D01]", targetDateString)
See https://docs.marklogic./xdmp.parseDateTime
Converting back to a string is just fn.string(yourdate)
you can directly use the constructor of date
class.
var d = new Date("2013-04-21");
console.log(d);
you can even use it with different formats, Ref.
本文标签: javascriptHow to convert string to date type in MarkLogicStack Overflow
版权声明:本文标题:javascript - How to convert string to date type in MarkLogic? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745440139a2658409.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论