Searching...
Wednesday, 4 June 2014

How to get current GMT and Current Local time in java?

00:19

Example

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class GMTExample {
public static void main(String[] args) throws ParseException {

SimpleDateFormat gmtDateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS Z");
gmtDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
String currentGMTDateString = gmtDateFormat.format(new Date());

SimpleDateFormat gmtDateFormat1 = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS Z");
String currentDateString = gmtDateFormat1.format(new Date());

System.out.println("Current GMT=" + currentGMTDateString
+ " Current Local" + currentDateString);

}

}

Output

Current GMT=04-06-2014 07:18:25.939 +0000 Current Local04-06-2014 12:48:25.940 +0530
 

0 comments: