There's a data in my solr: Using the Solr Administration User Interface, the modifyTime is "2016-04-20T13:58:35.805Z".
Using solrj: enter image description here, the modifyTime is "Wed Apr 20 21:58:35 CST 2016".
I'm using solr6. Why?
There's a data in my solr: Using the Solr Administration User Interface, the modifyTime is "2016-04-20T13:58:35.805Z".
Using solrj: enter image description here, the modifyTime is "Wed Apr 20 21:58:35 CST 2016".
I'm using solr6. Why?
modifyTime data format coming from Solr Administration User Interface is UTC, you can understand it by the Z at the end of datetime string, indicating that this string representation of the date is in UTC.
2016-04-20T13:58:35.805Z
On the other hand, modifyTime coming from data format is CST – Central China Standard Time, which in your case it seems to be + 8 hours.
Wed Apr 20 21:58:35 CST 2016
This happens because of a Java annoying and bad feature where the java.util.Date has no time zone yet it's toString method applies the JVM's current default time zone.
java.util.Date date = ( java.util.Date ) doc.getFieldValue("modifyTime");
DateTime dateTimeUtc = new DateTime( date, DateTimeZone.UTC );
String output = dateTimeUtc.toString();
EDIT
Thanks to @BasilBourque for the suggestion on the meaning of CST (Time Zone Abbreviation)
The answer by Alfredo is correct but for one assumption. That answer mentions Central Standard Time, but that zone is behind UTC (7 or 6 hours) while the data in the Question is ahead of UTC. So I presume CST
here refers to China Standard Time which is 8 ahead of UTC.
This confusion shows why we should never use these 3-4 letter abbreviations such as CST
. They are not true time zones, not standardized, and are not even unique (as we see here). Instead use proper tz/IANA time zones in the form of continent/region
.
The problem is the use of the old date-time classes. These poorly designed and notoriously troublesome classes have been supplanted in Java 8 and later by the java.time framework.
That string should be directly parsed by Instant
to get a value in UTC.
Instant instant = Instant.parse( "2016-04-20T13:58:35.805Z" );
Call toString
to get the same kind of string back, formatted according to the ISO 8601 standard.
Apply a time zone to see the same moment through the lens of a particular locality’s wall-clock time. Apply a ZoneId
to get a ZonedDateTime
object.
For the example of America/Montreal
the wall-clock time is four hours behind UTC, so the hour is 09
instead of 13
.
ZoneId zoneId = ZoneId.of( "America/Montreal" );
ZonedDateTime zdt = instant.atZone( zoneId );
2016-04-20T09:58:35.805-04:00[America/Montreal]
Both the Instant
and the ZonedDateTime
represent the same simultaneous point on the timeline.