Skip to content

Instantly share code, notes, and snippets.

@davidsan
Last active August 29, 2015 14:09
Show Gist options
  • Save davidsan/4f3cc33c4644f0a55bcb to your computer and use it in GitHub Desktop.
Save davidsan/4f3cc33c4644f0a55bcb to your computer and use it in GitHub Desktop.
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