用于比较的 Jackrabbit 日期格式
我正在使用 Jackrabbit 来存储我的文档。 现在我想使用 XPATH 搜索在特定日期之后创建的文档。为此,我尝试了以下方法:
String dateString = date.toString();
//element(*,nt:file)[@jcr:created >= xs:dateTime(dateString)]
date is an object of class java.util.Date
dateString 的格式为:Wed Mar 16 00:00:00 CET 2011
但这给了我一个 InvalidQueryException
,表明 dateString 是错误的:
无效查询:行中有词法错误 1,第136栏。遇到:“0”(48), after : ":" for 语句
所以问题是: xs:dateTime 的日期的正确格式是什么?
提前致谢
I am using Jackrabbit to store my documents.
Now I would like to search for documents that were created e.g. after a specific date using XPATH. To do so, I tried something like:
String dateString = date.toString();
//element(*,nt:file)[@jcr:created >= xs:dateTime(dateString)]
date is an object of class java.util.Date
dateString gets formatted as: Wed Mar 16 00:00:00 CET 2011
But this is giving me an InvalidQueryException
, indicating that the dateString is wrong:
Invalid query: Lexical error at line
1, column 136. Encountered: "0" (48),
after : ":" for statement
So the question is: What is the correct format of a date for xs:dateTime ?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于 Jackrabbit,这对我有用:
yyyy-MM-dd'T'HH:mm:ss.SSSX
(
2015-12-16T15:16:50.465-02:00
) 当之前的一些代码获取日历并完成时:prop.getValue().getString()
无法无法让 Z 工作(“无法解析的日期”)。
For Jackrabbit this worked for me:
yyyy-MM-dd'T'HH:mm:ss.SSSX
(
2015-12-16T15:16:50.465-02:00
) when some previous code had taken a Calendar and done:prop.getValue().getString()
Couldn't get Z to work ("Unparseable date").
只是为了完整起见:
我找到了另一种(Jackrabbit/JCR dependent)方法来获取格式正确的日期字符串:
此 dateString 可以与
xs:dateTime
的单个参数构造函数一起使用Just for the sake of completeness:
I found another (Jackrabbit/JCR dependend) way to get a correctly formatted date string:
This dateString can be used with the single arg constructor of
xs:dateTime
xs:dateTime
使用特定模式 - 请参阅 此处和此处。因此,您需要使用合适的DateFormat
来生成该格式,而不是使用 date.toString()。类似这样的:但是,xs:dateTime 的构造函数实际上需要两个参数:一个用于日期,一个用于时间。请参阅此处。
所以我猜你可以使用这个:
xs:dateTime
uses a specific pattern - see here and here. So instead of using date.toString(), to produce that format, you would need to use a suitableDateFormat
. Something like this:However, it appears that the constructor for xs:dateTime in fact requires two args: one for date and one for time. See here.
So I would guess you could use this:
另外,我对 JAckRabbit 日期格式有一些问题,我需要获取两个日期之间的一些实体:
@createdDate >= xs:dateTime(startDate)
@createdDate <= xs:dateTime(endDate)
我注意到的是:
使用格式 yyyy-MM-dd'T'HH:mm:ss.SSS'Z' 解析日期给出了错误的结果(也应该是 yyyy-MM-dd'T'HH:mm:ss.SSSZ) 但你会得到例如:
2012-01-04T23:59:59.999+0200 而不是
2012-01-04T23:59:59.999+02:00(保存在 JCR 中)
使用 ValueFactoryImpl.getInstance().createValue(cal).getString() 的解决方案有效。
Also I have some problems with JAckRabbit date format and I needed to get some entities between two dates :
@createdDate >= xs:dateTime(startDate)
@createdDate <= xs:dateTime(endDate)
What I noticed is :
using format yyyy-MM-dd'T'HH:mm:ss.SSS'Z' to parse the date gave incorrect results( also it should be yyyy-MM-dd'T'HH:mm:ss.SSSZ) but you get for example :
2012-01-04T23:59:59.999+0200 instead of
2012-01-04T23:59:59.999+02:00 (saved in JCR)
Solution with ValueFactoryImpl.getInstance().createValue(cal).getString() works.