当前位置: 首页>>代码示例>>Java>>正文


Java LocalDateTime.toLocalDate方法代码示例

本文整理汇总了Java中java.time.LocalDateTime.toLocalDate方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.toLocalDate方法的具体用法?Java LocalDateTime.toLocalDate怎么用?Java LocalDateTime.toLocalDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.LocalDateTime的用法示例。


在下文中一共展示了LocalDateTime.toLocalDate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_plusHours_one

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_plusHours_one() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate();

    for (int i = 0; i < 50; i++) {
        t = t.plusHours(1);

        if ((i + 1) % 24 == 0) {
            d = d.plusDays(1);
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), (i + 1) % 24);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:TCKLocalDateTime.java

示例2: test_plusMinutes_one

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_plusMinutes_one() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate();

    int hour = 0;
    int min = 0;

    for (int i = 0; i < 70; i++) {
        t = t.plusMinutes(1);
        min++;
        if (min == 60) {
            hour++;
            min = 0;
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:TCKLocalDateTime.java

示例3: test_minusHours_one

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_minusHours_one() {
    LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate();

    for (int i = 0; i < 50; i++) {
        t = t.minusHours(1);

        if (i % 24 == 0) {
            d = d.minusDays(1);
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:TCKLocalDateTime.java

示例4: dateToLocalDate

import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
 * This method returns the date passed as parameter converted to {@link LocalDate}. Be careful, {@link LocalDate} has no time information.
 * @param date {@link LocalDateTime}
 * @return {@link LocalDate}
 * @throws JSKException if some of the parameters are null.
 */
public static LocalDate dateToLocalDate(LocalDateTime date) throws JSKException {

    if (isNull(date)) {
        throw new JSKException(NULL_PARAMETERS);
    }
    
    return date.toLocalDate();
}
 
开发者ID:Varoso,项目名称:JSK,代码行数:15,代码来源:JSKDateConverter.java

示例5: test_plusSeconds_one

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_plusSeconds_one() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate();

    int hour = 0;
    int min = 0;
    int sec = 0;

    for (int i = 0; i < 3700; i++) {
        t = t.plusSeconds(1);
        sec++;
        if (sec == 60) {
            min++;
            sec = 0;
        }
        if (min == 60) {
            hour++;
            min = 0;
        }

        assertEquals(t.toLocalDate(), d);
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:TCKLocalDateTime.java

示例6: test_plusNanos_halfABillion

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_plusNanos_halfABillion() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = t.toLocalDate();

    int hour = 0;
    int min = 0;
    int sec = 0;
    int nanos = 0;

    for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
        t = t.plusNanos(500000000);
        nanos += 500000000;
        if (nanos == 1000000000) {
            sec++;
            nanos = 0;
        }
        if (sec == 60) {
            min++;
            sec = 0;
        }
        if (min == 60) {
            hour++;
            min = 0;
        }

        assertEquals(t.toLocalDate(), d, String.valueOf(i));
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
        assertEquals(t.getNano(), nanos);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:TCKLocalDateTime.java

示例7: convertLocalDateTimeToDate

import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
 * Converti une LocalDateTime en LocalDate
 * 
 * @param localDateTime
 * @return la date convertie
 */
public static LocalDate convertLocalDateTimeToDate(LocalDateTime localDateTime) {
	if (localDateTime == null) {
		return null;
	}
	return localDateTime.toLocalDate();
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:13,代码来源:MethodUtils.java

示例8: changeStartTime

import java.time.LocalDateTime; //导入方法依赖的package包/类
private void changeStartTime(MouseEvent evt) {
    LocalDateTime locationTime = dayView.getZonedDateTimeAt(evt.getX(), evt.getY()).toLocalDateTime();
    LocalDateTime time = grid(locationTime);

    LOGGER.finer("changing start time, time = " + time); //$NON-NLS-1$

    DraggedEntry draggedEntry = dayView.getDraggedEntry();

    if (isMinimumDuration(entry, entry.getEndAsLocalDateTime(), locationTime)) {

        Interval interval = draggedEntry.getInterval();

        LocalDate startDate = interval.getStartDate();
        LocalDate endDate = interval.getEndDate();

        LocalTime startTime;
        LocalTime endTime;

        if (locationTime.isAfter(entry.getEndAsLocalDateTime())) {
            startTime = entry.getEndTime();
            endTime = time.toLocalTime();
            endDate = time.toLocalDate();
        } else {
            startDate = time.toLocalDate();
            startTime = time.toLocalTime();
            endTime = entry.getEndTime();
        }

        LOGGER.finer("new interval: sd = " + startDate + ", st = " + startTime + ", ed = " + endDate + ", et = " + endTime);

        draggedEntry.setInterval(startDate, startTime, endDate, endTime);

        requestLayout();
    }
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:36,代码来源:DayViewEditController.java

示例9: changeEndTime

import java.time.LocalDateTime; //导入方法依赖的package包/类
private void changeEndTime(MouseEvent evt) {
    LocalDateTime locationTime = dayView.getZonedDateTimeAt(evt.getX(), evt.getY()).toLocalDateTime();
    LocalDateTime time = grid(locationTime);

    LOGGER.finer("changing end time, time = " + time); //$NON-NLS-1$

    DraggedEntry draggedEntry = dayView.getDraggedEntry();

    if (isMinimumDuration(entry, entry.getStartAsLocalDateTime(), locationTime)) {

        Interval interval = draggedEntry.getInterval();

        LOGGER.finer("dragged entry: " + draggedEntry.getInterval());

        LocalDate startDate = interval.getStartDate();
        LocalDate endDate = interval.getEndDate();

        LocalTime startTime;
        LocalTime endTime;

        if (locationTime.isBefore(entry.getStartAsLocalDateTime())) {
            endTime = entry.getStartTime();
            startTime = time.toLocalTime();
            startDate = time.toLocalDate();
        } else {
            startTime = entry.getStartTime();
            endTime = time.toLocalTime();
            endDate = time.toLocalDate();
        }

        LOGGER.finer("new interval: sd = " + startDate + ", st = " + startTime + ", ed = " + endDate + ", et = " + endTime);

        draggedEntry.setInterval(startDate, startTime, endDate, endTime);

        requestLayout();
    }
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:38,代码来源:DayViewEditController.java

示例10: changeStartAndEndTime

import java.time.LocalDateTime; //导入方法依赖的package包/类
private void changeStartAndEndTime(MouseEvent evt) {
    DraggedEntry draggedEntry = dayView.getDraggedEntry();
    LocalDateTime locationTime = dayView.getZonedDateTimeAt(evt.getX(), evt.getY()).toLocalDateTime();

    LOGGER.fine("changing start/end time, time = " + locationTime //$NON-NLS-1$
            + " offset duration = " + offsetDuration); //$NON-NLS-1$

    if (locationTime != null && offsetDuration != null) {

        LocalDateTime newStartTime = locationTime.minus(offsetDuration);
        newStartTime = grid(newStartTime);
        LocalDateTime newEndTime = newStartTime.plus(entryDuration);

        LOGGER.fine("new start time = " + newStartTime); //$NON-NLS-1$
        LOGGER.fine("new start time (grid) = " + newStartTime); //$NON-NLS-1$
        LOGGER.fine("new end time = " + newEndTime); //$NON-NLS-1$

        LocalDate startDate = newStartTime.toLocalDate();
        LocalTime startTime = newStartTime.toLocalTime();

        LocalDate endDate = LocalDateTime.of(startDate, startTime).plus(entryDuration).toLocalDate();
        LocalTime endTime = newEndTime.toLocalTime();

        LOGGER.finer("new interval: sd = " + startDate + ", st = " + startTime + ", ed = " + endDate + ", et = " + endTime);

        draggedEntry.setInterval(startDate, startTime, endDate, endTime);

        requestLayout();
    }
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:31,代码来源:DayViewEditController.java

示例11: test

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test() throws NoSuchMethodException, SecurityException, SQLException {
	PropertyMapperManager mapper = new PropertyMapperManager();
	LocalDateTime localDateTime = LocalDateTime.now();
	OffsetDateTime offsetDateTime = OffsetDateTime.of(localDateTime, OffsetDateTime.now().getOffset());
	ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, Clock.systemDefaultZone().getZone());

	java.sql.Timestamp timestamp = java.sql.Timestamp.valueOf(localDateTime);
	LocalDate localDate = localDateTime.toLocalDate();
	java.sql.Date date = java.sql.Date.valueOf(localDate);
	LocalTime localTime = localDateTime.toLocalTime();
	java.sql.Time time = new java.sql.Time(toTime(localTime));
	OffsetTime offsetTime = offsetDateTime.toOffsetTime();

	assertThat(mapper.getValue(JavaType.of(LocalDateTime.class), newResultSet("getTimestamp", timestamp), 1), is(localDateTime));
	assertThat(mapper.getValue(JavaType.of(OffsetDateTime.class), newResultSet("getTimestamp", timestamp), 1), is(offsetDateTime));
	assertThat(mapper.getValue(JavaType.of(ZonedDateTime.class), newResultSet("getTimestamp", timestamp), 1), is(zonedDateTime));
	assertThat(mapper.getValue(JavaType.of(LocalDate.class), newResultSet("getDate", date), 1), is(localDate));
	assertThat(mapper.getValue(JavaType.of(LocalTime.class), newResultSet("getTime", time), 1), is(localTime));
	assertThat(mapper.getValue(JavaType.of(OffsetTime.class), newResultSet("getTime", time), 1), is(offsetTime));

	assertThat(mapper.getValue(JavaType.of(LocalDateTime.class), newResultSet("getTimestamp", null), 1), is(nullValue()));
	assertThat(mapper.getValue(JavaType.of(OffsetDateTime.class), newResultSet("getTimestamp", null), 1), is(nullValue()));
	assertThat(mapper.getValue(JavaType.of(ZonedDateTime.class), newResultSet("getTimestamp", null), 1), is(nullValue()));
	assertThat(mapper.getValue(JavaType.of(LocalDate.class), newResultSet("getDate", null), 1), is(nullValue()));
	assertThat(mapper.getValue(JavaType.of(LocalTime.class), newResultSet("getTime", null), 1), is(nullValue()));
	assertThat(mapper.getValue(JavaType.of(OffsetTime.class), newResultSet("getTime", null), 1), is(nullValue()));

}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:30,代码来源:DateTimeApiPropertyMapperTest.java

示例12: testDateJava8

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void testDateJava8() throws ParseException, PebbleException, IOException
{
    PebbleEngine pebble = new PebbleEngine
        .Builder()
        .loader(new StringLoader())
        .strictVariables(false)
        .defaultLocale(Locale.ENGLISH)
        .build();

    final LocalDateTime localDateTime = LocalDateTime.of(2017, 6, 30, 13, 30, 35, 0);
    final ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, ZoneId.of("GMT+0100"));
    final LocalDate localDate = localDateTime.toLocalDate();
    final LocalTime localTime = localDateTime.toLocalTime();

    StringBuilder source = new StringBuilder();
    source
        .append("{{ localDateTime | date }}")
        .append("{{ localDateTime | date('yyyy-MM-dd HH:mm:ss') }}")
        .append("{{ zonedDateTime | date('yyyy-MM-dd HH:mm:ssXXX') }}")
        .append("{{ localDate | date('yyyy-MM-dd') }}")
        .append("{{ localTime | date('HH:mm:ss') }}");

    PebbleTemplate template = pebble.getTemplate(source.toString());
    Map<String, Object> context = new HashMap<>();
    context.put("localDateTime", localDateTime);
    context.put("zonedDateTime", zonedDateTime);
    context.put("localDate", localDate);
    context.put("localTime", localTime);

    Writer writer = new StringWriter();
    template.evaluate(writer, context);
    assertEquals("2017-06-30T13:30:352017-06-30 13:30:352017-06-30 13:30:35+01:002017-06-3013:30:35", writer.toString());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:35,代码来源:CoreFiltersTest.java

示例13: assertThat

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static DayAssert assertThat(LocalDateTime actual) {
    return new DayAssert(actual.toLocalDate());
}
 
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:4,代码来源:DayAssert.java

示例14: main

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static void main(String[] args) throws Throwable {
    int N = 10000;
    long t1970 = new java.util.Date(70, 0, 01).getTime();
    Random r = new Random();
    for (int i = 0; i < N; i++) {
        int days  = r.nextInt(50) * 365 + r.nextInt(365);
        long secs = t1970 + days * 86400 + r.nextInt(86400);
        int nanos = r.nextInt(NANOS_PER_SECOND);
        int nanos_ms = nanos / 1000000 * 1000000; // millis precision
        long millis = secs * 1000 + r.nextInt(1000);

        LocalDateTime ldt = LocalDateTime.ofEpochSecond(secs, nanos, ZoneOffset.UTC);
        LocalDateTime ldt_ms = LocalDateTime.ofEpochSecond(secs, nanos_ms, ZoneOffset.UTC);
        Instant inst = Instant.ofEpochSecond(secs, nanos);
        Instant inst_ms = Instant.ofEpochSecond(secs, nanos_ms);
        //System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);

        /////////// Timestamp ////////////////////////////////
        Timestamp ta = new Timestamp(millis);
        ta.setNanos(nanos);
        if (!isEqual(ta.toLocalDateTime(), ta)) {
            System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
            print(ta.toLocalDateTime(), ta);
            throw new RuntimeException("FAILED: j.s.ts -> ldt");
        }
        if (!isEqual(ldt, Timestamp.valueOf(ldt))) {
            System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
            print(ldt, Timestamp.valueOf(ldt));
            throw new RuntimeException("FAILED: ldt -> j.s.ts");
        }
        Instant inst0 = ta.toInstant();
        if (ta.getTime() != inst0.toEpochMilli() ||
            ta.getNanos() != inst0.getNano() ||
            !ta.equals(Timestamp.from(inst0))) {
            System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
            throw new RuntimeException("FAILED: j.s.ts -> instant -> j.s.ts");
        }
        inst = Instant.ofEpochSecond(secs, nanos);
        Timestamp ta0 = Timestamp.from(inst);
        if (ta0.getTime() != inst.toEpochMilli() ||
            ta0.getNanos() != inst.getNano() ||
            !inst.equals(ta0.toInstant())) {
            System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
            throw new RuntimeException("FAILED: instant -> timestamp -> instant");
        }

        ////////// java.sql.Date /////////////////////////////
        // j.s.d/t uses j.u.d.equals() !!!!!!!!
        java.sql.Date jsd = new java.sql.Date(millis);
        if (!isEqual(jsd.toLocalDate(), jsd)) {
            System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
            print(jsd.toLocalDate(), jsd);
            throw new RuntimeException("FAILED: j.s.d -> ld");
        }
        LocalDate ld = ldt.toLocalDate();
        if (!isEqual(ld, java.sql.Date.valueOf(ld))) {
            System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
            print(ld, java.sql.Date.valueOf(ld));
            throw new RuntimeException("FAILED: ld -> j.s.d");
        }
        ////////// java.sql.Time /////////////////////////////
        java.sql.Time jst = new java.sql.Time(millis);
        if (!isEqual(jst.toLocalTime(), jst)) {
            System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
            print(jst.toLocalTime(), jst);
            throw new RuntimeException("FAILED: j.s.t -> lt");
        }
        // millis precision
        LocalTime lt = ldt_ms.toLocalTime();
        if (!isEqual(lt, java.sql.Time.valueOf(lt))) {
            System.out.printf("ms: %16d  ns: %10d  ldt:[%s]%n", millis, nanos, ldt);
            print(lt, java.sql.Time.valueOf(lt));
            throw new RuntimeException("FAILED: lt -> j.s.t");
        }
    }
    System.out.println("Passed!");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:78,代码来源:JavatimeTest.java

示例15: Interval

import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
 * Constructs a new time interval with the given start and end dates /
 * times and time zone.
 *
 * @param startDateTime the start date and time (e.g. Oct. 3rd, 2015, 6:15pm)
 * @param endDateTime   the end date and time
 * @param zoneId        the time zone
 */
public Interval(LocalDateTime startDateTime, LocalDateTime endDateTime, ZoneId zoneId) {
    this(startDateTime.toLocalDate(), startDateTime.toLocalTime(), endDateTime.toLocalDate(), endDateTime.toLocalTime(), zoneId);
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:12,代码来源:Interval.java


注:本文中的java.time.LocalDateTime.toLocalDate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。