Pergunta

I am trying to parse in JAVA a date/time that I receive from an API.

The timestamp I receive looks like this: "Thu Feb 13 12:11:09 IST (Israel) 2014"

I am using Java's SimpleDateFormat, however I do not see anywhere how did the country name, with parentheses, arrive in this string, and how should I parse it.

Is this some standard format I don't know about?

UPDATE:

I am receiving this timestamp from an Android application. The funny thing is the exact same application, running on a different device gives me: "Tue Feb 04 17:36:31 GMT+02:00 2014"

GMT+2 is Israel as well, same timezone, different format... why??

Foi útil?

Solução

I don't know where android manages the time zone name resources. Anyway, obviously the resource names were changed on this one device (by Google?) with the motivation to avoid duplicates. The abbreviation IST is not unique and can also stand for "Indian Standard Time" which maps to Asia/Colcata instead (while Israel time zone is Asia/Jerusalem).

If you cannot parse "IST (Israel)" then I assume following things: If you parse it by SimpleDateFormat directly on android device then it should probably work. But if you get this string remotely then you can only apply preprocessing of string (filtering out the country) because other devices will not necessarily manage and share the same time zone name resources. You might be able to check directly on android what resources are stored there by calling DateFormatSymbols.getZoneStrings().

Conclusion: You should consider such strings as device-dependent. For data exchange, such formats are not well designed. Instead of using such proprietary formats you should try to use ISO-strings in formats like "yyyy-MM-dd'T'HH:mm:ssXX". Does the API you use offer any alternative format?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top