I am trying to convert a date(Date object) with one time zone (say IST) to a date in GMT. But i am getting a date which does have a changed time but the timezone it displays is still "IST". i want the timezone should be displayed as "GMT".
I used a Date object to get the final date after trying several conversions, which gave the converted date but the time zone was still "IST" in the output.
I then tried with DateTime object(Joda Time) :
Date dateIndia = new Date(); DateTime dateTime = new DateTime(dateIndia); DateTimeZone timeZone = DateTimeZone.forID("GMT"); DateTime date_UtcGmt = dateTime.toDateTime(timeZone); System.out.println("dateIndia : " + dateIndia); System.out.println("dateTime : " + dateTime); System.out.println("date_UtcGmt : " + date_UtcGmt); System.out.println("date_UtcGmt.toDate : " + date_UtcGmt.toDate());
It is showing me the following output :
dateIndia : Thu Sep 04 15:49:50 IST 2014
dateTime : 2014-09-04T15:49:50.152+05:30
date_UtcGmt : 2014-09-04T10:19:50.152Z
date_UtcGmt.toDate : Thu Sep 04 15:49:50 IST 2014
Now i have date_UtcGmt in GMT format but when i convert it to date, it is again in IST format. I want a date object which shows GMT as its time zone. Can i change the display format of date_UtcGmt object? What should i do?