Example usage for java.time LocalDateTime of

List of usage examples for java.time LocalDateTime of

Introduction

In this page you can find the example usage for java.time LocalDateTime of.

Prototype

public static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute) 

Source Link

Document

Obtains an instance of LocalDateTime from year, month, day, hour and minute, setting the second and nanosecond to zero.

Usage

From source file:Main.java

public static void main(String[] args) {
    // 2014-04-01 10:45
    LocalDateTime dateTime = LocalDateTime.of(2014, Month.APRIL, 1, 10, 45);

    // using a custom pattern (01/04/2014)
    String asCustomPattern = dateTime.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));

    System.out.println(asCustomPattern);
}

From source file:Main.java

public static void main(String[] args) {
    // using offsets
    LocalDateTime date = LocalDateTime.of(2013, Month.JULY, 20, 3, 30);
    ZoneOffset offset = ZoneOffset.of("+05:00");

    // 2013-07-20 22:30 +05:00
    OffsetDateTime plusFive = OffsetDateTime.of(date, offset);
    System.out.println(plusFive);

    // 2013-07-19 20:30 -02:00
    OffsetDateTime minusTwo = plusFive.withOffsetSameInstant(ZoneOffset.ofHours(-2));

    System.out.println(minusTwo);
}

From source file:Main.java

public static void main(String[] args) {
    // 2014-04-01 10:45
    LocalDateTime dateTime = LocalDateTime.of(2014, Month.APRIL, 1, 10, 45);

    // french date formatting (1. avril 2014)
    String frenchDate = dateTime.format(DateTimeFormatter.ofPattern("d. MMMM yyyy", new Locale("fr")));

    System.out.println(frenchDate);
}

From source file:Main.java

public static void main(String[] args) {
    ZoneId usCentral = ZoneId.of("America/Chicago");
    LocalDateTime localDateTime = LocalDateTime.of(2014, Month.MAY, 21, 9, 30);
    System.out.println(localDateTime);
    ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, usCentral);
    System.out.println(zonedDateTime);
}

From source file:Main.java

public static void main(String[] args) {
    ZoneId berlin = ZoneId.of("Europe/Berlin");

    // 2014-02-20 12:00
    LocalDateTime dateTime = LocalDateTime.of(2014, 02, 20, 12, 0);

    // 2014-02-20 12:00, Europe/Berlin (+01:00)
    ZonedDateTime berlinDateTime = ZonedDateTime.of(dateTime, berlin);

    System.out.println(berlinDateTime);
}

From source file:Main.java

public static void main(String[] args) {
    ZoneId usCentral = ZoneId.of("America/Chicago");
    LocalDateTime ldt = LocalDateTime.of(2012, Month.MARCH, 10, 7, 30);
    ZonedDateTime zdt1 = ZonedDateTime.of(ldt, usCentral);
    Period p1 = Period.ofDays(1);

    ZonedDateTime zdt2 = zdt1.plus(p1);
    System.out.println(zdt2);/*from w ww .  j a v a 2  s  .c  o  m*/
}

From source file:Main.java

public static void main(String[] args) {
    // 2014-04-01 10:45
    LocalDateTime dateTime = LocalDateTime.of(2014, Month.APRIL, 1, 10, 45);

    // using short german date/time formatting (01.04.14 10:45)
    DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
            .withLocale(new Locale("de"));
    String germanDateTime = dateTime.format(formatter);

    System.out.println(germanDateTime);
}

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime zdt1 = ZonedDateTime.now();
    System.out.println("Current zoned  datetime:" + zdt1);

    LocalDateTime ldt = LocalDateTime.of(2012, Month.MARCH, 11, 7, 30);

    ZoneId usCentralZone = ZoneId.of("America/Chicago");
    ZonedDateTime zdt2 = ZonedDateTime.of(ldt, usCentralZone);
    System.out.println(zdt2);/*  www  . j  a v  a 2 s  .c  o m*/
}

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime currentDateTime = LocalDateTime.now();
    System.out.println(currentDateTime); // 2014-06-27T09:04:47.527

    // 2014-10-02 12:30
    LocalDateTime secondAug2014 = LocalDateTime.of(2014, 10, 2, 12, 30);
    System.out.println(secondAug2014); // 2014-10-02T12:30

    // 2014-12-24 12:00
    LocalDateTime christmas2014 = LocalDateTime.of(2014, Month.DECEMBER, 24, 12, 0);
    System.out.println(christmas2014); // 2014-12-24T12:00
}

From source file:Main.java

public static void main(String[] args) {
    ZoneId berlin = ZoneId.of("Europe/Berlin");
    ZoneId losAngeles = ZoneId.of("America/Los_Angeles");
    // 2014-02-20 12:00
    LocalDateTime dateTime = LocalDateTime.of(2014, 02, 20, 12, 0);

    // 2014-02-20 12:00, Europe/Berlin (+01:00)
    ZonedDateTime berlinDateTime = ZonedDateTime.of(dateTime, berlin);

    // 2014-02-20 03:00, America/Los_Angeles (-08:00)
    ZonedDateTime losAngelesDateTime = berlinDateTime.withZoneSameInstant(losAngeles);

    System.out.println(losAngelesDateTime);
}