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) {
    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);

    int offsetInSeconds = losAngelesDateTime.getOffset().getTotalSeconds(); // -28800

    System.out.println(offsetInSeconds);
}

From source file:Main.java

public static void main(String[] args) {
    ZoneId usChicago = ZoneId.of("America/Chicago");

    // 2014-03-09T02:30 did not exist in America/Chicago time zone
    LocalDateTime ldt = LocalDateTime.of(2014, Month.MARCH, 9, 2, 30);
    ZonedDateTime zdt = ZonedDateTime.of(ldt, usChicago);
    System.out.println(zdt);//from  www . j a va  2  s . c o  m

    // 2013-10-03T01:30 existed twice in America/Chicago time zone
    LocalDateTime ldt2 = LocalDateTime.of(2013, Month.NOVEMBER, 3, 1, 30);
    ZonedDateTime zdt2 = ZonedDateTime.of(ldt2, usChicago);

    System.out.println(zdt2.withEarlierOffsetAtOverlap());
    System.out.println(zdt2.withLaterOffsetAtOverlap());

}

From source file:Main.java

public static void main(String[] args) {
    DateTimeFormatter format = DateTimeFormatter.ofPattern("MMM d yyyy  hh:mm a");
    LocalDateTime leaving = LocalDateTime.of(2013, Month.JULY, 20, 19, 30);

    // Leaving from San Francisco on July 20, 2013, at 7:30 p.m.

    ZoneId leavingZone = ZoneId.of("America/Los_Angeles");
    ZonedDateTime departure = ZonedDateTime.of(leaving, leavingZone);

    String out1 = departure.format(format);
    System.out.printf("LEAVING:  %s (%s)%n", out1, leavingZone);

    // Flight is 10 hours and 50 minutes, or 650 minutes
    ZoneId arrivingZone = ZoneId.of("Asia/Tokyo");
    ZonedDateTime arrival = departure.withZoneSameInstant(arrivingZone).plusMinutes(650);

    String out2 = arrival.format(format);
    System.out.printf("ARRIVING: %s (%s)%n", out2, arrivingZone);

}

From source file:Main.java

public static void main(String[] args) {
    LocalTime now = LocalTime.now();
    LocalTime currentTimeInLosAngeles = LocalTime.now(ZoneId.of("America/Los_Angeles"));
    System.out.println(String.format("now is %s and in LA is %s", now, currentTimeInLosAngeles));

    ZoneId leavingZone = ZoneId.of("Asia/Tel_Aviv");
    ZoneId arrivingZone = ZoneId.of("America/New_York");

    LocalDateTime leaving = LocalDateTime.of(2014, Month.JULY, 16, 23, 00);
    ZonedDateTime departure = ZonedDateTime.of(leaving, leavingZone);

    ZonedDateTime arrival = departure.withZoneSameInstant(arrivingZone).plusHours(11).plusMinutes(51);

    DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-d  HH:mm");
    System.out.println(String.format("Departure: %s", departure.format(format)));
    System.out.println(String.format("Arrival: %s", arrival.format(format)));
}

From source file:Main.java

public static void main(String[] argv) {

    LocalDateTime now = LocalDateTime.now();
    ZonedDateTime zonedDateTime = ZonedDateTime.of(now, TimeZone.NEW_YORK);
    System.out.println("now = " + now);
    System.out.println("Current date and time in a particular timezone : " + zonedDateTime);

    now = LocalDateTime.now(TimeZone.INDIA);
    System.out.println("now in India = " + now);

    zonedDateTime = ZonedDateTime.now();
    System.out.println("zonedDateTime with default(system) timezone = " + zonedDateTime);
    System.out.println("zonedDateTime with India timezone = " + ZonedDateTime.now(TimeZone.INDIA));

    String isoFormatted = DateTimeFormatter.ISO_INSTANT.format(ZonedDateTime.now(TimeZone.INDIA));
    System.out.println("ISO Formatted = " + isoFormatted);

    ZonedDateTime utahMarch8thAt2AM = ZonedDateTime.of(LocalDateTime.of(2015, 3, 8, 1, 0), TimeZone.UTAH);
    System.out.println("utahMarch8thAt2AM = " + utahMarch8thAt2AM);
    System.out.println("utahMarch8thAt2AM.plusHours(1) = " + utahMarch8thAt2AM.plusHours(1));
    System.out.println("utahMarch8thAt2AM.plusHours(2) = " + utahMarch8thAt2AM.plusHours(2));
}

From source file:Main.java

public static void main(String[] args) {

    // the current date
    LocalDate currentDate = LocalDate.now();

    // 2014-02-10
    LocalDate tenthFeb2014 = LocalDate.of(2014, Month.FEBRUARY, 10);

    // months values start at 1 (2014-08-01)
    LocalDate firstAug2014 = LocalDate.of(2014, 8, 1);

    // the 65th day of 2010 (2010-03-06)
    LocalDate sixtyFifthDayOf2010 = LocalDate.ofYearDay(2010, 65);

    // times, e.g. 19:12:30.733

    LocalTime currentTime = LocalTime.now(); // current time
    LocalTime midday = LocalTime.of(12, 0); // 12:00
    LocalTime afterMidday = LocalTime.of(13, 30, 15); // 13:30:15

    // 12345th second of day (03:25:45)
    LocalTime fromSecondsOfDay = LocalTime.ofSecondOfDay(12345);

    // dates with times, e.g. 2014-02-18T19:08:37.950
    LocalDateTime currentDateTime = LocalDateTime.now();

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

    // 2014-12-24 12:00
    LocalDateTime christmas2014 = LocalDateTime.of(2014, Month.DECEMBER, 24, 12, 0);

    // current (local) time in Los Angeles
    LocalTime currentTimeInLosAngeles = LocalTime.now(ZoneId.of("America/Los_Angeles"));

    // current time in UTC time zone
    LocalTime nowInUtc = LocalTime.now(Clock.systemUTC());

    System.out.println("date/time creation: currentDate: " + currentDate);
    System.out.println("date/time creation: tenthFeb2014: " + tenthFeb2014);
    System.out.println("date/time creation: firstAug2014: " + firstAug2014);
    System.out.println("date/time creation: sixtyFifthDayOf2010: " + sixtyFifthDayOf2010);
    System.out.println("date/time creation: currentTime: " + currentTime);
    System.out.println("date/time creation: midday: " + midday);
    System.out.println("date/time creation: afterMidday: " + afterMidday);
    System.out.println("date/time creation: fromSecondsOfDay: " + fromSecondsOfDay);
    System.out.println("date/time creation: currentTimeInLosAngeles: " + currentTimeInLosAngeles);
    System.out.println("date/time creation: currentDateTime: " + currentDateTime);
    System.out.println("date/time creation: secondAug2014: " + secondAug2014);
    System.out.println("date/time creation: christmas2014: " + christmas2014);
}

From source file:dhbw.clippinggorilla.external.twitter.TwitterUtils.java

public static void main(String[] args) {
    Set<String> includedTagsSet = new HashSet<>();
    Set<String> excludedTagsSet = new HashSet<>();
    LocalDateTime date;/*from   w w w. j  av a  2s.co m*/

    includedTagsSet.add("bmw, mercedes");
    includedTagsSet.add("Audi, toyota");
    includedTagsSet.add("merkel");
    includedTagsSet.add("dat boi, pepe");
    includedTagsSet.add("dhbw");
    includedTagsSet.add("VW Golf");

    Query query = queryBuilder(includedTagsSet, LocalDateTime.of(2017, 5, 1, 0, 0));

    QueryResult result = searchTweets(query);

    for (Status status : result.getTweets()) {
        System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText());
        for (MediaEntity mediaEntity : status.getMediaEntities()) {
            System.out.println(mediaEntity.getType());
        }
        System.out.println("_________________________________________________");
    }
}

From source file:org.ligoj.app.plugin.prov.aws.auth.AWS4SignerForAuthorizationHeaderTest.java

/**
 * Test method for//from   w  ww.j  a v a 2 s . c o m
 * {@link org.ligoj.app.plugin.prov.aws.auth.AWS4SignerForAuthorizationHeader#computeSignature(org.ligoj.app.plugin.prov.aws.auth.AWS4SignatureQuery)}.
 */
@Test
public void testComputeSignature() {
    ReflectionTestUtils.setField(signer, "clock", Clock.fixed(
            LocalDateTime.of(2017, 5, 29, 22, 15).toInstant(ZoneOffset.UTC), ZoneOffset.UTC.normalized()));
    final AWS4SignatureQuery signatureQuery = AWS4SignatureQuery.builder().accessKey("awsAccessKey")
            .secretKey("awsSecretKey").region("eu-west-1").method("GET").service("s3").path("path").build();
    Assertions.assertEquals(
            "AWS4-HMAC-SHA256 Credential=awsAccessKey/20170529/eu-west-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=6a48aa41b25ea6d1b0e636c78ea971de060256ea2a2b2e6b103d6fbf14c7d21a",
            signer.computeSignature(signatureQuery));
}

From source file:eu.off.db.entity.MemberTest.java

@Test
public void BuildMinimalMember() {

    LocalDateTime dateTime = LocalDateTime.of(1978, Month.APRIL, 4, 0, 0);
    Date birthday = Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());

    Member aMember = new MemberBuilder(LAST_NAME, FIRST_NAME, STREET, ZIP_CODE, PLACE, COUNTRY, birthday,
            GENDER, NATIONALITY).build();

    assertThat(aMember.getLastName().equals(LAST_NAME));
    assertThat(aMember.getFirstName().equals(FIRST_NAME));
    assertThat(aMember.getAdress().equals(STREET));
    assertThat(aMember.getZipCode().equals(ZIP_CODE));
    assertThat(aMember.getPlace().equals(PLACE));
    assertThat(aMember.getCountry().equals(COUNTRY));
    assertThat(aMember.getBirthday().equals(birthday));
    assertThat(aMember.getGender().equals(GENDER));
    assertThat(aMember.getNationality().equals(NATIONALITY));
}

From source file:org.ligoj.app.plugin.prov.aws.auth.AWS4SignerForAuthorizationHeaderTest.java

/**
 * Test method for/*from   w ww. j a va2  s  . c  o  m*/
 * {@link org.ligoj.app.plugin.prov.aws.auth.AWS4SignerForAuthorizationHeader#computeSignature(org.ligoj.app.plugin.prov.aws.auth.AWS4SignatureQuery)}.
 */
@Test
public void testComputeSignatureWithBody() {
    ReflectionTestUtils.setField(signer, "clock", Clock.fixed(
            LocalDateTime.of(2017, 5, 29, 22, 15).toInstant(ZoneOffset.UTC), ZoneOffset.UTC.normalized()));
    final AWS4SignatureQuery signatureQuery = AWS4SignatureQuery.builder().accessKey("awsAccessKey")
            .secretKey("awsSecretKey").region("eu-west-1").method("GET").service("s3").path("path").body("body")
            .build();
    Assertions.assertEquals(
            "AWS4-HMAC-SHA256 Credential=awsAccessKey/20170529/eu-west-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=704a07b30cf11a27123ea3b430680a37ffe311a858496440ab519d0cc5adaa8f",
            signer.computeSignature(signatureQuery));
}