fork download
  1. import java.time.ZoneId;
  2. import java.time.ZonedDateTime;
  3. import java.time.format.DateTimeFormatter;
  4. import java.time.format.DateTimeFormatterBuilder;
  5. import java.time.format.TextStyle;
  6. import java.util.Locale;
  7. import java.util.Set;
  8.  
  9. class Main {
  10. public static void main(String[] args) {
  11. Set<ZoneId> preferredZones = Set.of(ZoneId.of("Asia/Kolkata"));
  12. DateTimeFormatter dtf = new DateTimeFormatterBuilder()
  13. .appendPattern("EEE MMM dd HH:mm:ss")
  14. .appendLiteral(' ')
  15. .appendZoneText(TextStyle.SHORT, preferredZones)
  16. .appendLiteral(' ')
  17. .appendPattern("uuuu")
  18. .toFormatter(Locale.ENGLISH);
  19.  
  20. ZonedDateTime zdt = ZonedDateTime.parse("Mon Apr 08 00:00:00 IST 2013", dtf);
  21. System.out.println(zdt);
  22. }
  23. }
Success #stdin #stdout 0.4s 66476KB
stdin
Standard input is empty
stdout
2013-04-08T00:00+05:30[Asia/Kolkata]