-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathgmt.java
46 lines (37 loc) · 1.08 KB
/
gmt.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Java Program to convert local time to GMT
// Importing libraries
// 1. input output libraries
import java.io.*;
// 3. Text class
import java.text.DateFormat;
import java.text.SimpleDateFormat;
// 2. Utility libraries for
// Date and TimeZone class
import java.util.Date;
import java.util.TimeZone;
// Class
class GFG {
// Main driver method
public static void main(String[] args)
{
// Creating a Date class object
// to take local time from the user
Date localTime = new Date();
// Creating a DateFormat class object to
// convert the localtime to GMT
DateFormat s = new SimpleDateFormat("dd/MM/yyyy"
+ " "
+ " HH:mm:ss");
// function will helps to get the GMT Timezone
// using the getTimeZOne() method
s.setTimeZone(TimeZone.getTimeZone("GMT"));
// One can get any other time zone also
// by passing some other argument to it
// Printing the local time
System.out.println("local Time:" + localTime);
// Printing the GMT time to
// illustrate changes in GMT time
System.out.println("Time IN Gmt : "
+ s.format(localTime));
}
}