Lucene dateToString, stringToDate

I am in a locale where the time is two hours ahead of GMT + 2. When I encode the date using the new GregorianCalendar (y, m, d, d, h, m, s) and then use DateTools.dateToString with DAY permission, I I get a day earlier.

Coding 12:00 midnight 1,1,1970 As a result, I get January 31 (22:00), which is clearly wrong. The problem is even worse because stringToDate does not return me the same number.

Apparently this monstrous design confusion.

What is the right way to compensate for this so that you can correctly find the date of birth.

thanks

+4
source share
1 answer

What constructor do you use to create GregorianCalendar? If you do not specify a time zone, it will simply use the default value, which is the time zone of the machine on which you are running the code.

Make sure the Date object you pass to dateToString is correctly set to GMT. On the search side, you will also need to normalize requests for the date in GMT as well.

It is impossible to bypass normalization - you donโ€™t know where the code will be executed, so you need to bind your dates, normalizing to GMT

+3
source

All Articles