开发者

Jackrabbit dateformat for comparison

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 formatt开发者_如何转开发ed 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


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").


Just for the sake of completeness:

I found another (Jackrabbit/JCR dependend) way to get a correctly formatted date string:

Calendar cal = Calendar.getInstance();
cal.setTime(date);
String dateString = ValueFactoryImpl.getInstance().createValue(cal).getString();

This dateString can be used with the single arg constructor of 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 suitable DateFormat. Something like this:

DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
String dateString = format.format(date);

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:

DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
DateFormat tf = new SimpleDateFormat("HH:mm:ss");
String dateString = df.format(date);
String timeString = tf.format(date);


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 :

  1. 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)

  2. Solution with ValueFactoryImpl.getInstance().createValue(cal).getString() works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜