fork download
  1. import java.text.ParseException;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4. import java.util.Locale;
  5. import java.util.TimeZone;
  6.  
  7. public class Main {
  8. public static void main(String[] args) throws ParseException {
  9. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.ENGLISH);
  10. Date date = sdf.parse("2011-11-19T00:00:00.000-05:00");
  11.  
  12. // Display date in UTC/GMT
  13. sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
  14. System.out.println(sdf.format(date));
  15.  
  16. // Display date in the timezone with an offset of -05:00 hours
  17. sdf.setTimeZone(TimeZone.getTimeZone("GMT-05:00"));
  18. System.out.println(sdf.format(date));
  19. }
  20. }
Success #stdin #stdout 0.15s 56464KB
stdin
Standard input is empty
stdout
2011-11-19T05:00:00.000Z
2011-11-19T00:00:00.000-05:00