fork(13) 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:ssXXX", Locale.ENGLISH);
  10. Date date = sdf.parse("2013-09-29T18:46:19Z");
  11.  
  12. // In JVM's timezone and default format as returned by Date#toString
  13. System.out.println(date);
  14.  
  15. // In UTC and custom format
  16. sdf.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
  17. String strDate = sdf.format(date);
  18. System.out.println(strDate);
  19.  
  20. // In India and custom format
  21. sdf.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata"));
  22. strDate = sdf.format(date);
  23. System.out.println(strDate);
  24. }
  25. }
Success #stdin #stdout 0.22s 55112KB
stdin
Standard input is empty
stdout
Sun Sep 29 18:46:19 GMT 2013
2013-09-29T18:46:19Z
2013-09-30T00:16:19+05:30