Possible Duplicate:
Get GMT Time in Java
I have taken the reference of the below 2 link :
But I want the GMT date in milliseconds.
Thanks In Advance.
Possible Duplicate:
Get GMT Time in Java
I have taken the reference of the below 2 link :
But I want the GMT date in milliseconds.
Thanks In Advance.
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
long time = cal.getTimeInMillis();
System.currentTimeMillis()
which returns the time in millis for GMT. –
Wanyen long
for that too. –
Wanyen You can use System.currentTimeMillis() it returns "the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC."
long time = System.currentTimeMillis();
Will do it :)
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
long time = cal.getTimeInMillis();
System.currentTimeMillis()
which returns the time in millis for GMT. –
Wanyen long
for that too. –
Wanyen Use the Calendar Class to create an instance with GMT as the timezone.
From that you can get the time in milliseconds.
see below code sample.
public class TimeTest {
public static void main(String [] args) {
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
System.out.println(cal.currentTimeMillis());
}
}
Hope this helps.
System.currentTimeMillis()
and also if you are using Calendar
prefer cal.getTimeInMillis()
instead of cal.getTime().getTime()
–
Carmellacarmelle Use getTime() function:
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
© 2022 - 2024 — McMap. All rights reserved.