I am converting the current date to GMT time.
The result is in-consistent, due to this my date time calculations are going worng.
DateTimeFormat df = DateTimeFormat.getFormat("dd MMM yyyy hh:mm:ss");
String gmtStr = new Date().toGMTString().replace("GMT", "").trim();
long deptime= depTime - df.parse(gmtStr).getTime();
deptime = deptime / 1000;
seconds = (deptime % 60);
minutes = (deptime % 3600) / 60;
hours = (deptime / 3600);
Not sure what the best way is, but you could use the getTimezoneOffsert
:
final Date gmtDate = new Date();
final Date offDate = new Date(gmtDate.getTime() + gmtDate.getTimezoneOffset() * 60 * 1000);
The offDate
when displayed with DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_LONG)
will still show the utc/gmt offset, because basically you have create a new time in the current timezone, but it matches the time of the GMT time and the long value returned from getTime()
will be the number of milliseconds you can use in your calculation.