3

I am trying to get the difference in seconds in GMT time and Local time but i am unable to get using System.currentTimeMillis()

GMT: Wed, 15 Apr 2015 14:54:39 GMT

Your time zone: 4/15/2015, 8:24:39 PM GMT+5:30 (Asia/Calcutta)

What i need is the timestamps in milliseconds or seconds of the GMT time and my local time so that i can calculate their difference's

Rahul Gupta
  • 5,275
  • 8
  • 35
  • 66

3 Answers3

9

I think you may over-thinking your problem.

You can get an object representing the current Time Zone by:

TimeZone timezone = TimeZone.getDefault();

And then, use the getRawOffset() method, that returns the number of milliseconds that timezone is offset from UTC (which is equivalent to GMT).

timezone.getRawOffset();

Doing a calculation is over-kill.

TZHX
  • 5,291
  • 15
  • 47
  • 56
1

@Rahul Gupta, once you have obtained the Date object from the above dates, you can use

Date.getTime()

to get the milliseconds equivalent. You can refer this as well http://docs.oracle.com/javase/6/docs/api/java/util/Date.html

Santhana
  • 233
  • 1
  • 5
  • While not incorrect, this returns the absolute time, in milliseconds since Epoch. More info: https://stackoverflow.com/a/57220021/2102748 – milosmns Jul 26 '19 at 12:30
1

Difference has been defined by the GMT code, if your GMT is +/- 5.30 ,

then difference is = 5 * 60 *60 + 30 * 60 seconds

Heshan Sandeepa
  • 3,388
  • 2
  • 35
  • 45