fork download
  1. import java.text.SimpleDateFormat;
  2. import java.util.Date;
  3. import java.util.Locale;
  4. import java.util.TimeZone;
  5.  
  6. public class Main {
  7. public static void main(String[] args) {
  8. Date date = new Date();
  9.  
  10. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.ENGLISH);
  11.  
  12. sdf.setTimeZone(TimeZone.getTimeZone("America/New_York"));
  13. String strDateNewYork = sdf.format(date);
  14. System.out.println(strDateNewYork);
  15.  
  16. sdf.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
  17. String strDateUtc = sdf.format(date);
  18. System.out.println(strDateUtc);
  19. }
  20. }
Success #stdin #stdout 0.19s 56304KB
stdin
Standard input is empty
stdout
2021-06-20T09:44:43.969-04:00
2021-06-20T13:44:43.969Z