Skip to content

Instantly share code, notes, and snippets.

@vaibhav-jani
Last active August 2, 2017 11:34
Show Gist options
  • Select an option

  • Save vaibhav-jani/cec7a472da50640585fc11e76047e41b to your computer and use it in GitHub Desktop.

Select an option

Save vaibhav-jani/cec7a472da50640585fc11e76047e41b to your computer and use it in GitHub Desktop.
Java date format quickey
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
public class DateFormatterDemo {
public static void main(String[] args) throws Exception {
String target = "Wed, 02 Aug 2017 14:03:56 IST";
DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss z", Locale.US);
Date result = df.parse(target);
System.out.println(result);
TimeZone gmtTime = TimeZone.getTimeZone("GMT");
df.setTimeZone(gmtTime);
System.out.println("Current DateTime in GMT : " + df.format(result));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment