datetime conversion is off by 1 hour?
Hi,
I have a rest call, with a datetime value of "2016-06-10T13:00:00Z" when it's imported into realm model, the value is 10 Jun 2016, 14:00:00
Is this a bug?
Realm version(s): 0.87.0
Android Studio version: 1.5
Which Android version and device: 4.4.4 api19 genymotion
What is your timezone?
The final Z at the end of the string is part of the ISO 8601 standard and stands for Zulu, which means UTC. If you don't like in a UTC zone, the Date class will take care of the conversion.
I'm not setting any timezones. I'm just reading some rest data, and using copyToRealmOrUpdate to generate the model data. I'm in the UK; so my timezone is BST. Also, if I remove the Z, it fails to convert the string into the realm object.
How are you checking the date? Calling Date.toString() will just use the default timezone when formatting the date. For BST that currently means +1 compared to UTC due to summer time.
Z is GMT
BST is GMT+1
Your Date instance receives the millis and uses the Locale of the current timezone, which is BST, which is GMT+1
Which means that 10 Jun 2016, 13:00:00 in GMT is actually 10 Jun 2016, 14:00:00 in BST
So in this case, java.util.Date is working as intended
Like most databases, Realm stores time/date as UTC i.e., with no information about timezone. We don't provide a time/date-with-timezone type. I guess we could clarify that in the documentation.
Fun fact: Iceland is the only country which has been in the same time zone (no summer/winter time).
Hi,
ok, thanks. Quick question, Using "2016-06-10T13:00:00BST" fails ( realm fails to read the data and convert to object). Is that as expected also?
Yes, adding BST is not a valid ISO8601 format you need to specify the offset using +xx:yy: https://en.wikipedia.org/wiki/ISO_8601