java - How to format the given time string and convert to date/time object -
i getting time object in form of string rest service . need extract time , time operation.the given time string "2015-06-16t14:58:48z". tried below code , convert string time , , getting incorrect values.
string time = "2015-06-16t14:58:48z"; simpledateformat formatter = new simpledateformat("yyyy-mm-dd't'hh:mm:ss'z'", locale.us); string dateinstring = "2015-06-16t14:58:48z"; date date = formatter.parse(dateinstring); system.out.println("original string : " + time); system.out.println("after converting time : " + formatter.format(date)); the output getting below: original string : 2015-06-16t14:58:48z after converting time : 2015-12-362t02:58:48z
the converted date somehow getting wrong value.please suggest mistake.thanks.
you format string has couple of mistakes:
ymeans week year, not year,ydmeans day of year. should have usedd, means day of month.hmeans 12-hour notation time of day. since have14should useh, handle 24-hour notation.
to sum up:
simpledateformat formatter = new simpledateformat("yyyy-mm-dd't'hh:mm:ssx", locale.us);
Comments
Post a Comment