fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.time.LocalDate;
  6. import java.time.ZoneOffset;
  7. import java.time.format.DateTimeFormatter;
  8. import java.time.temporal.TemporalAccessor;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. String abc = "2017-01-03+01:00";
  16. TemporalAccessor parsed = DateTimeFormatter.ISO_OFFSET_DATE.parse(abc);
  17. LocalDate date = LocalDate.from(parsed);
  18. ZoneOffset offset = ZoneOffset.from(parsed);
  19. System.out.println("Date: " + date + "; offset: " + offset + '.');
  20.  
  21. Date oldfashionedDate = Date.from(date.atStartOfDay(offset).toInstant());
  22. TimeZone oldfashionedTimeZone = TimeZone.getTimeZone(offset);
  23. System.out.println("Old-fashioned date: " + oldfashionedDate
  24. + "; old-fashioned time-zone: " + oldfashionedTimeZone.getDisplayName() + '.');
  25. }
  26. }
Success #stdin #stdout 0.24s 35808KB
stdin
Standard input is empty
stdout
Date: 2017-01-03; offset: +01:00.
Old-fashioned date: Mon Jan 02 23:00:00 GMT 2017; old-fashioned time-zone: GMT+01:00.