java - SimpleDateFormat.parse() converts DTstring to local time. Can be converted to source's time? -
i have followed so answer datetime conversion of 8601.
i cite example straight w3 :
1994-11-05t08:15:30-05:00 corresponds november 5, 1994, 8:15:30 am, eastern standard time. 1994-11-05t13:15:30z corresponds same instant.
and run in android
simpledateformat sdfsource = new simpledateformat("yyyy-mm-dd't'hh:mm:sszzzzz"); datetime = sdfsource.parse("2014-03-06t11:30:00-05:00"); system.out.println(datetime); //thu mar 06 18:30:00 eet 2014
obviously .parse()'s output local aware datetime. there has been conversion est
(-05:00) eet
(+02:00) since in timezone. not want auto-convertion.
is there way parse datetime string inyyyy-mm-dd't'hh:mm:sszzzzz
format , display that timezone's datetime? preferable output:
thu mar 06 11:30:00 est 2014
the est
, location example. can other timezones well.
internally date
objects in utc , that's they're parsed to.
you cannot retrieve original timezone date
can attempt retrieve original iso-8601 stamp, , use when formatting.
when convert string tostring()
, uses local settings format date. if want specific representation, use formatter format output, e.g.
int rawtimezoneoffsetmillis = ...; // retrieve iso-8601 stamp , convert milliseconds timezone tz = new simpletimezone(rawtimezoneoffsetmillis, "name"); dateformat outputformat = dateformat.getdatetimeinstance(); outputformat.settimezone(tz); system.out.println(df.format(datetime));
iso-8601 timestamps not parseable simpledateformat
. this answer has code work around of limitations.
Comments
Post a Comment