Java Code Examples for java.time.LocalDateTime.of()

The following are Jave code examples for showing how to use of() of the java.time.LocalDateTime class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jdk8u-jdk   File: ZoneOffsetTransitionRule.java   View Source Code Vote up 6 votes
/**
 * Creates a transition instance for the specified year.
 * <p>
 * Calculations are performed using the ISO-8601 chronology.
 *
 * @param year  the year to create a transition for, not null
 * @return the transition instance, not null
 */
public ZoneOffsetTransition createTransition(int year) {
    LocalDate date;
    if (dom < 0) {
        date = LocalDate.of(year, month, month.length(IsoChronology.INSTANCE.isLeapYear(year)) + 1 + dom);
        if (dow != null) {
            date = date.with(previousOrSame(dow));
        }
    } else {
        date = LocalDate.of(year, month, dom);
        if (dow != null) {
            date = date.with(nextOrSame(dow));
        }
    }
    if (timeEndOfDay) {
        date = date.plusDays(1);
    }
    LocalDateTime localDT = LocalDateTime.of(date, time);
    LocalDateTime transition = timeDefinition.createDateTime(localDT, standardOffset, offsetBefore);
    return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter);
}
 
Example 2
Project: jdk8u-jdk   File: TCKLocalDateTime.java   View Source Code Vote up 6 votes
@Test
public void test_get_TemporalField() {
    LocalDateTime test = LocalDateTime.of(2008, 6, 30, 12, 30, 40, 987654321);
    assertEquals(test.get(ChronoField.YEAR), 2008);
    assertEquals(test.get(ChronoField.MONTH_OF_YEAR), 6);
    assertEquals(test.get(ChronoField.DAY_OF_MONTH), 30);
    assertEquals(test.get(ChronoField.DAY_OF_WEEK), 1);
    assertEquals(test.get(ChronoField.DAY_OF_YEAR), 182);

    assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12);
    assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30);
    assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40);
    assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321);
    assertEquals(test.get(ChronoField.HOUR_OF_AMPM), 0);
    assertEquals(test.get(ChronoField.AMPM_OF_DAY), 1);
}
 
Example 3
Project: kqsse17   File: Quiz.java   View Source Code Vote up 6 votes
public boolean checkDateTime(){ /// not working...?
    LocalDateTime currentDateTime = LocalDateTime.now();
       // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss");
       // String nowDate = currentDateTime.format(formatter);
      
        String[] datarrayString = date.split("-");
        String[] timeendarray = "23:59:59".split(":");
        
        
        LocalDateTime pickedTimeEnd = LocalDateTime.of(Integer.parseInt(datarrayString[0]),Integer.parseInt(datarrayString[1]),Integer.parseInt(datarrayString[2]), Integer.parseInt(timeendarray[0]), Integer.parseInt(timeendarray[1]), Integer.parseInt(timeendarray[2]));
              
        if(pickedTimeEnd.isBefore(currentDateTime)){
            return false;
        }
        //else if(pickedTimeEnd.isBefore(currentDateTime)){
            
          //  return false;
        //}
        else{
            System.out.print(pickedTimeEnd +"  "+currentDateTime);
            return true;
        }

}
 
Example 4
Project: openjdk-jdk10   File: TCKZonedDateTime.java   View Source Code Vote up 5 votes
@Test
public void test_withZoneSameLocal_retainOffset2() {
    LocalDateTime ldt = LocalDateTime.of(2008, 11, 2, 1, 30, 59, 0);  // overlap
    ZonedDateTime base = ZonedDateTime.of(ldt, ZoneId.of("UTC-05:00") );
    ZonedDateTime test = base.withZoneSameLocal(ZoneId.of("America/New_York"));
    assertEquals(base.getOffset(), ZoneOffset.ofHours(-5));
    assertEquals(test.getOffset(), ZoneOffset.ofHours(-5));
}
 
Example 5
Project: jdk8u-jdk   File: TCKLocalDateTime.java   View Source Code Vote up 5 votes
@Test
public void factory_ofEpochSecond_longOffset_beforeEpoch() {
    LocalDateTime base = LocalDateTime.of(1970, 1, 1, 2, 0, 0, 500);
    for (int i = 0; i < 100000; i++) {
        LocalDateTime test = LocalDateTime.ofEpochSecond(-i, 500, OFFSET_PTWO);
        assertEquals(test, base.minusSeconds(i));
    }
}
 
Example 6
Project: jdk8u-jdk   File: TCKChronoField.java   View Source Code Vote up 5 votes
@DataProvider(name="fieldAndAccessor")
Object[][] data_fieldAndAccessor() {
    return new Object[][] {
            {YEAR, LocalDate.of(2000, 2, 29), true, 2000},
            {YEAR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 2000},
            {MONTH_OF_YEAR, LocalDate.of(2000, 2, 29), true, 2},
            {MONTH_OF_YEAR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 2},
            {DAY_OF_MONTH, LocalDate.of(2000, 2, 29), true, 29},
            {DAY_OF_MONTH, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 29},
            {DAY_OF_YEAR, LocalDate.of(2000, 2, 29), true, 60},
            {DAY_OF_YEAR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 60},

            {HOUR_OF_DAY, LocalTime.of(5, 4, 3, 200), true, 5},
            {HOUR_OF_DAY, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 5},

            {MINUTE_OF_DAY, LocalTime.of(5, 4, 3, 200), true, 5*60 + 4},
            {MINUTE_OF_DAY, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 5*60 + 4},
            {MINUTE_OF_HOUR, LocalTime.of(5, 4, 3, 200), true, 4},
            {MINUTE_OF_HOUR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 4},

            {SECOND_OF_DAY, LocalTime.of(5, 4, 3, 200), true, 5*3600 + 4*60 + 3},
            {SECOND_OF_DAY, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 5*3600 + 4*60 + 3},
            {SECOND_OF_MINUTE, LocalTime.of(5, 4, 3, 200), true, 3},
            {SECOND_OF_MINUTE, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 3},

            {NANO_OF_SECOND, LocalTime.of(5, 4, 3, 200), true, 200},
            {NANO_OF_SECOND, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 200},

            {YEAR, LocalTime.of(5, 4, 3, 200), false, -1},
            {MONTH_OF_YEAR, LocalTime.of(5, 4, 3, 200), false, -1},
            {DAY_OF_MONTH, LocalTime.of(5, 4, 3, 200), false, -1},
            {DAY_OF_YEAR, LocalTime.of(5, 4, 3, 200), false, -1},
            {HOUR_OF_DAY, LocalDate.of(2000, 2, 29), false, -1},
            {MINUTE_OF_DAY, LocalDate.of(2000, 2, 29), false, -1},
            {MINUTE_OF_HOUR, LocalDate.of(2000, 2, 29), false, -1},
            {SECOND_OF_DAY, LocalDate.of(2000, 2, 29), false, -1},
            {SECOND_OF_MINUTE, LocalDate.of(2000, 2, 29), false, -1},
            {NANO_OF_SECOND, LocalDate.of(2000, 2, 29), false, -1},
    };
}
 
Example 7
Project: openjdk-jdk10   File: TCKZonedDateTime.java   View Source Code Vote up 5 votes
@Test
public void test_minusMinutes_minutes() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.minusMinutes(30);
    assertEquals(test, ZonedDateTime.of(ldt.minusMinutes(30), ZONE_0100));
}
 
Example 8
Project: tenhou-visualizer   File: DownloadService.java   View Source Code Vote up 5 votes
private InfoSchema parseLineToInfo(String line, LocalDate localDate) {
    String[] columns = line.split(" \\| ");
    Matcher matcher = mjlogPattern.matcher(columns[3]);
    if (matcher.find()) {
        String id = matcher.group(1);
        if (this.databaseService.existsIdInINFO(id)) return null;

        boolean isSanma = columns[2].substring(0, 1).equals("三");
        boolean isTonnan = columns[2].substring(2, 3).equals("南");
        int minute = Integer.parseInt(columns[1]);
        String[] playerAndScore = columns[4].split(" ");
        String[] players = new String[4];
        int[] scores = new int[4];
        for (int i = 0; i < playerAndScore.length; i++) {
            Matcher playerMatcher = playerPattern.matcher(playerAndScore[i]);
            if (playerMatcher.find()) {
                players[i] = playerMatcher.group(1);
                scores[i] = (int) Float.parseFloat(playerMatcher.group(2));
            }
        }
        LocalTime localTime = LocalTime.from(DateTimeFormatter.ofPattern("HH:mm").parse(columns[0]));
        LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
        return new InfoSchema.Builder(id, isSanma, isTonnan, localDateTime,
                players[0], players[1], players[2], players[3])
                .minute(minute)
                .firstScore(scores[0])
                .secondScore(scores[1])
                .thirdScore(scores[2])
                .fourthScore(scores[3])
                .build();
    }

    return null;
}
 
Example 9
Project: graphql_java_gen   File: IntegrationTest.java   View Source Code Vote up 5 votes
@Test
public void testScalarInput() throws Exception {
    LocalDateTime ttl = LocalDateTime.of(2017, 1, 31, 10, 9, 48);
    String queryString = Generated.mutation(mutation -> mutation
        .setInteger(new Generated.SetIntegerInput("answer", 42).setTtl(ttl))
    ).toString();
    assertEquals("mutation{set_integer(input:{key:\"answer\",value:42,ttl:\"2017-01-31T10:09:48\"})}", queryString);
}
 
Example 10
Project: java-se8-oca-study-guide   File: Camera.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
    int hours;
    LocalDateTime now = LocalDateTime.of(220, 10, 01, 0, 0);
    LocalDate before = now.toLocalDate().minusDays(1);
    LocalTime after = now.toLocalTime().plusHours(1);

    /*while (before.isBefore(after) && hours < 4) {
        ++hours;
    }*/

}
 
Example 11
Project: jdk8u-jdk   File: TCKZonedDateTime.java   View Source Code Vote up 5 votes
@Test
public void test_plusMonths_zero() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusMonths(0);
    assertEquals(test, base);
}
 
Example 12
Project: openjdk-jdk10   File: TCKLocalDateTime.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_6intsMonth_secondTooLow() {
    LocalDateTime.of(2007, Month.JULY, 15, 12, 30, -1, 987654321);
}
 
Example 13
Project: jdk8u-jdk   File: TCKLocalDateTime.java   View Source Code Vote up 4 votes
@Test(dataProvider="sampleDateTimes")
public void test_equals_false_day_differs(int y, int m, int d, int h, int mi, int s, int n) {
    LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
    LocalDateTime b = LocalDateTime.of(y, m, d + 1, h, mi, s, n);
    assertFalse(a.equals(b));
}
 
Example 14
Project: openjdk-jdk10   File: TCKLocalDateTime.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_7ints_minuteTooHigh() {
    LocalDateTime.of(2007, 7, 15, 12, 60, 40, 987654321);
}
 
Example 15
Project: openjdk-jdk10   File: TCKLocalDateTime.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_7ints_dayTooHigh() {
    LocalDateTime.of(2007, 7, 32, 12, 30, 40, 987654321);
}
 
Example 16
Project: jdk8u-jdk   File: TCKLocalDateTime.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_6ints_hourTooLow() {
    LocalDateTime.of(2007, 7, 15, -1, 30, 40);
}
 
Example 17
Project: openjdk-jdk10   File: TCKLocalDateTime.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_7ints_monthTooLow() {
    LocalDateTime.of(2007, 0, 15, 12, 30, 40, 987654321);
}
 
Example 18
Project: openjdk-jdk10   File: TCKLocalDateTime.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_7ints_nanoTooLow() {
    LocalDateTime.of(2007, 7, 15, 12, 30, 40, -1);
}
 
Example 19
Project: openjdk-jdk10   File: TCKLocalDateTime.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_7ints_hourTooLow() {
    LocalDateTime.of(2007, 7, 15, -1, 30, 40, 987654321);
}
 
Example 20
Project: 360w17g1   File: JobDateTime.java   View Source Code Vote up 2 votes
/**
 * Sets the current date from the date string.
 * 
 * <p>Example: 02/02/2017 or 2/2/2017.</p>
 * 
 * @param dateString a string in the format MM/dd/yyyy
 * @return a reference to this job date for chaining
 * @throws ParseException if the string is not well formed
 * @throws NullPointerException if the date string is null
 */
public JobDateTime setFromDateString(final String dateString) throws ParseException {
	SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT);
	myDate = LocalDateTime.of(LocalDate.parse(df.format(df.parse(dateString)), myDateFormatter), myDate.toLocalTime());
	return this;
}