fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.* ;
  8. import java.time.format.* ;
  9. import java.time.temporal.* ;
  10. import java.time.chrono.* ;
  11.  
  12.  
  13. /* Name of the class has to be "Main" only if the class is public. */
  14. class Ideone
  15. {
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18.  
  19. OffsetDateTime time = OffsetDateTime.parse(
  20. "2024-11-26T16:30:00.000-05:00"
  21. );
  22. OffsetDateTime newTime = time
  23. .atZoneSameInstant(ZoneId.of("America/New_York"))
  24. .withYear(2024)
  25. .withMonth(11)
  26. .withDayOfMonth(26)
  27. .toOffsetDateTime();
  28.  
  29. OffsetDateTime utcTime = time
  30. .atZoneSameInstant(ZoneId.of("UTC"))
  31. .withYear(2024)
  32. .withMonth(11)
  33. .withDayOfMonth(26)
  34. .toOffsetDateTime();
  35.  
  36.  
  37. System.out.println(newTime.toString());
  38. System.out.println(utcTime.toString());
  39. }
  40. }
Success #stdin #stdout 0.18s 57632KB
stdin
Standard input is empty
stdout
2024-11-26T16:30-05:00
2024-11-26T21:30Z