Solr Index uses UTC time format … Zulu time zone (GMT).
“A date field shall be of the form 1995-12-31T23:59:59Z The trailing “Z” designates UTC time and is mandatory ”
Say your class has a property expiryDate … create another property indexedExpiryDate and index the later field.
So if you want to send data to the index you have to format it …
public Date getIndexedExpiryDate(){
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ss.SSS’Z'”);
Date indexFormatExpiryDate = sdf.parse(sdf.format(getExpiryDate()));
System.out.println(“indexFormatExpiry: “+indexFormatExpiry);
setIndexedExpiryDate(indexFormatExpiryDate );
return indexFormatExpiryDate
}
When you read it back from the index into the bean … it will automatically setIndexedExpiryDate with the date/time local time zone.
How ever, the index itself will hold the date in ZULU time (GMT) … so if you query the index directly you need to adjust for time zone … as queries will not be adjusted for local time zone.
If you are in IST that is 5hrs 30mins ahead of GMT … the query needs to be …
indexedExpiryDate :[NOW/DAY-5DAY-30MINUTES to *] … to get all entities with indexedExpiryDate >= today
Useful links …
UTC – Coordinated Universal Time
Kirk True (@kirk_true)
September 4, 2012
Awesome — that was exactly the date format I was looking for! Thanks!