Beispiel #1
0
  static void f2() {
    LocalTime time = LocalTime.of(20, 30);
    int hour = time.getHour(); // 20
    int minute = time.getMinute(); // 30
    time = time.withSecond(6); // 20:30:06
    time = time.plusMinutes(3); // 20:33:06

    System.out.println(hour);
    System.out.println(minute);
    System.out.println(time);
  }
Beispiel #2
0
 public static void main(String[] args) {
   LocalDate date = LocalDate.of(2015, Month.JULY, 6);
   LocalTime time = LocalTime.of(15, 25);
   LocalDateTime dateTime = LocalDateTime.of(date, time);
   printSectionName("LocalDateTime");
   System.out.println(dateTime);
   System.out.println(dateTime.minusDays(1));
   System.out.println(dateTime.minusHours(5));
   System.out.println(dateTime.minusSeconds(7));
   printDelimiterString();
 }
Beispiel #3
0
  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);
  }
Beispiel #4
0
  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);
  }
Beispiel #5
0
 @Test(expectedExceptions = DateTimeException.class)
 public void test_factory_CalendricalObject_invalid_noDerive() {
   Month.from(LocalTime.of(12, 30));
 }
 public void setDateAndTime(int day, int month, int year, int hour, int minute, int second) {
   LocalDate dateToSet = LocalDate.of(day, month, year);
   LocalTime timeToSet = LocalTime.of(hour, minute, second);
   dateAndTime = LocalDateTime.of(dateToSet, timeToSet);
 }
 public void setTime(int hour, int minute, int second) {
   LocalDate currentDate = LocalDate.from(dateAndTime);
   LocalTime timeToSet = LocalTime.of(hour, minute, second);
   dateAndTime = LocalDateTime.of(currentDate, timeToSet);
 }