public static void main(String[] args) { ZonedDateTime apollo11launch = ZonedDateTime.of(1969, 7, 16, 9, 32, 0, 0, ZoneId.of("America/New_York")); String formatted = DateTimeFormatter.ISO_DATE_TIME.format(apollo11launch); // 1969-07-16T09:32:00-05:00[America/New_York] System.out.println(formatted); DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG); formatted = formatter.format(apollo11launch); // July 16, 1969 9:32:00 AM EDT System.out.println(formatted); formatted = formatter.withLocale(Locale.FRENCH).format(apollo11launch); // 16 juillet 1969 09:32:00 EDT System.out.println(formatted); formatter = DateTimeFormatter.ofPattern("E yyyy-MM-dd HH:mm"); formatted = formatter.format(apollo11launch); System.out.println(formatted); LocalDate churchsBirthday = LocalDate.parse("1903-06-14"); System.out.println("churchsBirthday: " + churchsBirthday); apollo11launch = ZonedDateTime.parse( "1969-07-16 03:32:00-0400", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssxx")); System.out.println("apollo11launch: " + apollo11launch); }
public static ZonedDateTime getNextSchedule() { ZonedDateTime next_schedule; // Determine type of schedule if (ConfigHandler.backupInterval > 0) // Interval { next_schedule = ZonedDateTime.ofInstant( Instant.ofEpochMilli( System.currentTimeMillis() + (ConfigHandler.backupInterval * 60 * 1000)), ZoneId.systemDefault()); } else // Schedule { if (ConfigHandler.backupSchedule.length == 0) { return null; } LocalTime now = LocalTime.now(); LocalTime next_time = null; LocalDate day = LocalDate.now(); TreeSet<LocalTime> times = new TreeSet<>(); for (String s : ConfigHandler.backupSchedule) { times.add(LocalTime.parse(s, DateTimeFormatter.ofPattern("H:mm"))); } for (LocalTime t : times) // try to find next scheduled time for today { if (t.compareTo(now) == 1) { next_time = t; break; } } if (next_time == null) // if we couldn't find one for today take the first schedule time for tomorrow { day = day.plusDays(1); next_time = times.first(); } next_schedule = ZonedDateTime.of(day, next_time, ZoneId.systemDefault()); } return next_schedule; }
public static void main(String[] args) { LocalDateTime localDateTime = LocalDateTime.of(2016, 3, 27, 1, 20); localDateTime = localDateTime.plusHours(1); System.out.println(localDateTime); ZoneId zoneId = ZoneId.of("Europe/Warsaw"); ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, zoneId); System.out.println(zonedDateTime); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); result = prime * result + ((birthdate == null) ? 0 : birthdate.hashCode()); result = prime * result + ((active == null) ? 0 : active.hashCode()); result = prime * result + ((role == null) ? 0 : role.hashCode()); result = prime * result + ((email == null) ? 0 : email.hashCode()); return result; }
private static void newAPI() { LocalDate soloFecha = LocalDate.now(); LocalTime soloHora = LocalTime.now(); LocalDateTime todo = LocalDateTime.now(); ZonedDateTime zonedDateTime = ZonedDateTime.now(); System.out.println("La fecha " + soloFecha); System.out.println("La hora " + soloHora); System.out.println("La fecha hora " + todo); System.out.println("La fecha hora y zona " + zonedDateTime); LocalDate myFecha = LocalDate.of(2015, Month.JULY, 2); LocalTime myHora = LocalTime.of(9, 21); System.out.println("Ayer fue: " + myFecha); System.out.println("La hora fue: " + myHora); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final SignUpResponse other = (SignUpResponse) obj; if ((id == null && other.id != null) || !id.equals(other.id)) return false; if ((firstName == null && other.firstName != null) || !firstName.equals(other.firstName)) return false; if ((lastName == null && other.lastName != null) || !lastName.equals(other.lastName)) return false; if ((birthdate == null && other.birthdate != null) || !birthdate.equals(other.birthdate)) return false; if ((active == null && other.active != null) || !active.equals(other.active)) return false; if ((role == null && other.role != null) || !role.equals(other.role)) return false; if ((email == null && other.email != null) || !email.equals(other.email)) return false; return true; }
public static void main(String[] args) { ZonedDateTime apollo11launch = ZonedDateTime.of(1969, 7, 16, 9, 32, 0, 0, ZoneId.of("America/New_York")); // 1969-07-16T09:32-04:00[America/New_York] System.out.println("apollo11launch: " + apollo11launch); Instant instant = apollo11launch.toInstant(); System.out.println("instant: " + instant); ZonedDateTime zonedDateTime = instant.atZone(ZoneId.of("UTC")); System.out.println("zonedDateTime: " + zonedDateTime); ZonedDateTime skipped = ZonedDateTime.of( LocalDate.of(2013, 3, 31), LocalTime.of(2, 30), ZoneId.of("Europe/Berlin")); // Constructs March 31 3:30 System.out.println("skipped: " + skipped); ZonedDateTime ambiguous = ZonedDateTime.of( LocalDate.of(2013, 10, 27), // End of daylight savings time LocalTime.of(2, 30), ZoneId.of("Europe/Berlin")); // 2013-10-27T02:30+02:00[Europe/Berlin] ZonedDateTime anHourLater = ambiguous.plusHours(1); // 2013-10-27T02:30+01:00[Europe/Berlin] System.out.println("ambiguous: " + ambiguous); System.out.println("anHourLater: " + anHourLater); ZonedDateTime meeting = ZonedDateTime.of( LocalDate.of(2013, 10, 31), LocalTime.of(14, 30), ZoneId.of("America/Los_Angeles")); System.out.println("meeting: " + meeting); ZonedDateTime nextMeeting = meeting.plus(Duration.ofDays(7)); // Caution! Won’t work with daylight savings time System.out.println("nextMeeting: " + nextMeeting); nextMeeting = meeting.plus(Period.ofDays(7)); // OK System.out.println("nextMeeting: " + nextMeeting); }
@Override public ZonedDateTime convert(Date source) { return source == null ? null : ZonedDateTime.ofInstant(source.toInstant(), ZoneId.systemDefault()); }
@Override public Date convert(ZonedDateTime source) { return source == null ? null : Date.from(source.toInstant()); }