Last active
August 2, 2017 11:34
-
-
Save vaibhav-jani/cec7a472da50640585fc11e76047e41b to your computer and use it in GitHub Desktop.
Java date format quickey
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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