java - String date to GMT date but it is showing EST -


i want date displayed in gmt "01/01/2100"

expecting result - "fri jan 01 00:00:00 gmt 2100"

result seeing - "thu dec 31 19:00:00 est 2099"

  simpledateformat sdf = new simpledateformat("dd/mm/yyyy");   sdf.settimezone(timezone.gettimezone("gmt"));   try{        date mydate = sdf.parse("01/01/2100");            system.out.println(mydate);    }   catch(exception e){    } 

i want result mydate in gmt time not est

example 2

  simpledateformat sdf = new simpledateformat("yyyy-mm-dd hh:mm:ss");   sdf.settimezone(timezone.gettimezone("gmt"));   try{        date mydate = sdf.parse("2010-05-23 09:01:02");         simpledateformat df = new simpledateformat("eee, d mmm yyyy, hh:mm");       system.out.println("mydate: " +df.format(mydate));    }   catch(exception e){    } 

output: sun, 23 may 2010, 05:01

expecting: sun, 23 may 2010, 09:01

http://goo.gl/uiy9rq - url project code, run , check result

as stated in comments have apply date format date. modified code display mydate

try{      simpledateformat sdf = new simpledateformat("dd/mm/yyyy");      sdf.settimezone(timezone.gettimezone("gmt"));      date mydate = sdf.parse("01/01/2100");      system.out.println(sdf.format(mydate));      sdf.settimezone(timezone.gettimezone("est"));      system.out.println(sdf.format(mydate)); } catch(exception e){      // error handling } 

output

01/01/2100 31/12/2099 

but not forget date still contains information hours, minutes, seconds etc. in respect applied date formatter information not shown when running

system.out.println(sdf.format(mydate)); 

if need set fields of date, should make use of calendar.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -