java - String to Date conversion is losing time -
does know why date losing time values when converting string ? cannot seem figure 1 out.
here type of simpledateformat
using:
simpledateformat simpledateformat = new simpledateformat("eee mm/dd/yyyy hh:mm a");
the date trying convert string in form :
string datestring = "mon 06/23/2014 03:00 pm";
and when following:
date convertdatefromstring = null; try{ convertdatefromstring = simpledateformat.parse(datestring); }catch(parseexception ex){ ex.printstacktrace(); } system.out.println(convertdatefromstring.gettime());
my output is: 1403496000000
and expected output is: 1403550000000
can me understand why time not being parsed?
update - solved --->> of jon skeet
now using simpledateformat
simpledateformat simpledateformat = new simpledateformat("eee mm/dd/yyyy hh:mm a", locale.getdefault());
and output correct.
you've specified hh
in format, 24-hour format. you've also got am/pm designator.
as such, "03:00 pm" doesn't make sense - it's simultaneously trying represent 3am (03 in 24 hours) , 3pm (pm in data).
it sounds want hh
in format string, 12-hour specifier.
that's part of problem. next time zone. expected value (1403550000000) represents 2014-06-23 19:00:00z. presumably you're expecting use time zone 4 hours behind utc.
your actual value (1403496000000) @ moment 2014-06-23 04:00:00z... appears being parsed in time zone 1 hour behind utc.
you need work out time zone data meant in, , specify explicitly in simpledateformat
.
Comments
Post a Comment