I am trying to print the current date in GMT
Format but it is getting only in IST
format.
public static void main(String[] args) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy MMM dd HH:mm:ss zzz");
Date date = new Date();
System.out.println("Local Time: " + sdf.format(date));
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println("GMT Time : " + sdf.format(date));
Date date1=new SimpleDateFormat("yyyy MMM dd HH:mm:ss zzz").parse(sdf.format(date));
System.out.println("\t"+date1);
}
This is my output
Local Time: 2019 Apr 08 19:48:23 IST
GMT Time : 2019 Apr 08 14:18:23 GMT
Mon Apr 08 19:48:23 IST 2019
but i want to like this 2019 Apr 08 14:18:23 GMT
after parsing the string to date.