Get GMT Time in Milliseconds Using JAVA

Possible duplicate:
Get GMT GMT in Java

I took the link to the link below 2:

link1 link2

But I need the GMT date in milliseconds.

Thanks in advance.

+4
source share
4 answers

Use Calendar#getTimeInMillis :

 Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); long time = cal.getTimeInMillis(); 
+15
source

You can use System.currentTimeMillis () , which returns the "difference, measured in milliseconds, between current time and midnight, January 1, 1970 UTC.

 long time = System.currentTimeMillis(); 

Let's do it:)

+18
source

Use the Calendar class to instantiate with GMT as the time zone.

From this you can get the time in milliseconds.

see below for sample code.

 public class TimeTest { public static void main(String [] args) { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); System.out.println(cal.currentTimeMillis()); } } 

Hope this helps.

0
source

Use the getTime () function :

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT. represented by this Date object.

0
source

Source: https://habr.com/ru/post/1441505/


All Articles