Reputation: 14089
I'm trying to debug some inconsistencies with the parsing of time zones with SimpleDateFormat
here is the date format, I'm using to parse:
static private final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd, h:mmaa zzz", Locale.US);
Date string to parse :
2013-03-20, 3:36PM EDT
Parsing fails on Samsung with 2.3.5 works on HTC with 4.0.4 and HTC with 2.3.3.
Here is the output for some parsing tests:
HTC 4.0.4 :
Test : 2013-03-20, 3:36PM EST : Wed Mar 20 21:36:00 CET 2013 : lenient : true
Test : 2013-03-20, 3:36PM EDT : Wed Mar 20 20:36:00 CET 2013 : lenient : true
Test : 2013-03-20, 3:36PM EST : Wed Mar 20 21:36:00 CET 2013 : lenient : false
Test : 2013-03-20, 3:36PM EDT : Wed Mar 20 20:36:00 CET 2013 : lenient : false
HTC 2.3.3 :
Test : 2013-03-20, 3:36PM EST : Wed Mar 20 21:36:00 GMT+01:00 2013 : lenient : true
Test : 2013-03-20, 3:36PM EDT : Wed Mar 20 20:36:00 GMT+01:00 2013 : lenient : true
Test : 2013-03-20, 3:36PM EST : Wed Mar 20 21:36:00 GMT+01:00 2013 : lenient : false
Test : 2013-03-20, 3:36PM EDT : Wed Mar 20 20:36:00 GMT+01:00 2013 : lenient : false
Samsung 2.3.5 :
Test : 2013-03-20, 3:36PM EST : Wed Mar 20 21:36:00 GMT+01:00 2013 : lenient : true
Test : 2013-03-20, 3:36PM EST : Wed Mar 20 21:36:00 GMT+01:00 2013 : lenient : false
Rest of the parsings fail on the Samsung.
Can anybody explain this behavior?
Upvotes: 0
Views: 300
Reputation: 587
I'm having similar issue on a Samsung Galaxy 7 tablet.
"EDT" is not in the list returned by TimeZone.getAvailableIDs(), so a SimpleDateFormat using "z" does not work.
I'm going to make a hash table of TZ abbreviations and convert the codes to += offset.
Unbelievable, really...
Upvotes: 0
Reputation: 9276
There is no JDK available on Android at the moment.
And looking at the reference of SimpleDateFormat there is only one version of it. so whatever works on any android OS level should work on all levels. The inconstancy of SimpleDateFormat is most likely due to different locale on different devices. to fix that use one locale instead of using the device's default Locale.
new SimpleDateFormat(dataFormat,Locale.US);
Upvotes: 1
Reputation: 4269
Don't know about android, but in java you can get the system properties with: java.lang.System.getProperties()
Upvotes: 1