fork download
  1. import java.time.OffsetDateTime;
  2. import java.time.ZoneOffset;
  3.  
  4. class Main {
  5. public static void main(String[] args) {
  6. String strDateTime = "2023-01-09T23:51:44.595Z";
  7. String utcOffset = "UTC +6";
  8. int offsetHour = Integer.parseInt(utcOffset.replaceAll("[^0-9+-]", ""));
  9. ZoneOffset zoneOffset = ZoneOffset.ofHours(offsetHour);
  10. OffsetDateTime odtGiven = OffsetDateTime.parse(strDateTime);
  11. OffsetDateTime odtDesired = odtGiven.withOffsetSameLocal(zoneOffset)
  12. .withOffsetSameInstant(zoneOffset.UTC);
  13. System.out.println(odtDesired);
  14. }
  15. }
Success #stdin #stdout 0.12s 49444KB
stdin
Standard input is empty
stdout
2023-01-09T17:51:44.595Z