Last active
August 29, 2015 14:09
-
-
Save davidsan/4f3cc33c4644f0a55bcb to your computer and use it in GitHub Desktop.
This file contains 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
package timezone; | |
import java.text.DateFormat; | |
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
import java.util.Date; | |
import java.util.GregorianCalendar; | |
import java.util.TimeZone; | |
public class Main { | |
public static void main(String[] args) { | |
// formatter | |
DateFormat formatter = new SimpleDateFormat("yyyy-dd-MM'T'HH:mm:ss'Z'"); | |
formatter.setTimeZone(TimeZone.getTimeZone("Zulu")); | |
// parsage | |
Calendar cal = javax.xml.bind.DatatypeConverter.parseDateTime("2010-01-01T12:00:00Z"); | |
Date date = cal.getTime(); | |
String dateStr = formatter.format(date); | |
System.out.println(dateStr); | |
// date actuelle | |
Calendar currentCal = new GregorianCalendar(TimeZone.getTimeZone("Zulu")); | |
date = currentCal.getTime(); | |
dateStr = formatter.format(date); | |
System.out.println(dateStr); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment