java - Converting UTC date from server into local time -


i getting string date server

2016-06-11t11:14:57.000z 

since utc, want convert local time.

simpledateformat mformat = new simpledateformat("yyyy-mm-dd't'hh:mm:ss.sss'z'"); simpledateformat endformat = new simpledateformat("hh:mm a"); mformat.settimezone(timezone.gettimezone("gmt+5:00")); date date = mformat.parse(mbooking.starttime); 

however date converted 2:00am

now don't why 11am getting converted 2:00am

what wrong doing?

because don't set timezone each simpledateformat indeed mformat should set utc , endformat gmt + 5, here supposed do:

simpledateformat mformat = new simpledateformat("yyyy-mm-dd't'hh:mm:ss.sss'z'"); // set utc original date format input timezone mformat.settimezone(timezone.gettimezone("utc")); date date = mformat.parse("2016-06-11t11:14:57.000z"); simpledateformat endformat = new simpledateformat("hh:mm a"); // set gmt + 5 target date format output timezone endformat.settimezone(timezone.gettimezone("gmt+5:00"));  system.out.println(endformat.format(date)); 

output:

04:14 pm 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -