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


Java LocalDateTime.toLocalTime方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: splitDatesIntoMonths

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static List<Date[]> splitDatesIntoMonths(Date from, Date to) throws IllegalArgumentException {

    List<Date[]> dates = new ArrayList<>();

    LocalDateTime dFrom = asLocalDateTime(from);
    LocalDateTime dTo = asLocalDateTime(to);

    if (dFrom.compareTo(dTo) >= 0) {
      throw new IllegalArgumentException("Provide a to-date greater than the from-date");
    }

    while (dFrom.compareTo(dTo) < 0) {
      // check if current time frame is last
      boolean isLastTimeFrame = dFrom.getMonthValue() == dTo.getMonthValue() && dFrom.getYear() == dTo.getYear();

      // define day of month based on timeframe. if last - take boundaries from end date, else end of month and date
      int dayOfMonth = isLastTimeFrame ? dTo.getDayOfMonth() : dFrom.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
      LocalTime time = isLastTimeFrame ? dTo.toLocalTime() : LocalTime.MAX;


      // build timeframe
      Date[] dar = new Date[2];
      dar[0] = asDate(dFrom);
      dar[1] = asDate(dFrom.withDayOfMonth(dayOfMonth).toLocalDate().atTime(time));

      // add current timeframe
      dates.add(dar);

      // jump to beginning of next month
      dFrom = dFrom.plusMonths(1).withDayOfMonth(1).toLocalDate().atStartOfDay();
    }

    return dates;

  }
 
开发者ID:YagelNasManit,项目名称:environment.monitor,代码行数:36,代码来源:DataUtils.java

示例5: 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

示例6: deserializeValue

import java.time.LocalDateTime; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T deserializeValue(QueryExpression<T> expression, Object value) {
	if (value != null) {

		// date and times
		Optional<TemporalType> temporalType = JdbcDatastoreUtils.getTemporalType(expression, true);
		if (temporalType.isPresent()) {

			LocalDateTime dt = null;
			if (TypeUtils.isString(value.getClass())) {
				dt = asDateTime((String) value, temporalType.orElse(TemporalType.DATE));
			} else if (TypeUtils.isNumber(value.getClass())) {
				dt = asDateTime((Number) value);
			}

			if (dt != null) {
				if (LocalDateTime.class.isAssignableFrom(expression.getType())) {
					return (T) dt;
				}
				if (LocalDate.class.isAssignableFrom(expression.getType())) {
					return (T) dt.toLocalDate();
				}
				if (LocalTime.class.isAssignableFrom(expression.getType())) {
					return (T) dt.toLocalTime();
				}
				if (Date.class.isAssignableFrom(expression.getType())) {
					return (T) ConversionUtils.fromLocalDateTime(dt);
				}
			}
		}
	}

	// fallback to default
	return SQLValueDeserializer.getDefault().deserializeValue(expression, value);
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jdbc,代码行数:37,代码来源:SQLiteDialect.java

示例7: 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

示例8: testCreateGetAndDeleteGroup

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void testCreateGetAndDeleteGroup() throws Exception {
    clockService.setMockTime(LocalTime.of(10, 0)); // We're not allowed to create signups at night, so mocking time
    final LocalDateTime now = clockService.getCurrentDateTime();
    final LocalTime nowTime = now.toLocalTime();
    LocalDateTime endOfRaid = now.plusMinutes(45);
    final Gym gym = gymRepository.findByName("Blenda", uppsalaRegion);
    Raid enteiRaid = new Raid(pokemonRepository.search("Entei", null), endOfRaid, gym, localeService, uppsalaRegion);
    String raidCreatorName = "testUser1";
    User user = mock(User.class);
    when(user.getName()).thenReturn(raidCreatorName);
    Guild guild = mock(Guild.class);
    Config config = mock(Config.class);
    Raid enteiRaid1 = enteiRaid;
    try {
        enteiRaid1 = repo.newRaid(user, enteiRaid1, guild, config, "test");
    } catch (RuntimeException e) {
        System.err.println(e.getMessage());
        fail("Could not save raid: " + e.getMessage());
    }
    enteiRaid = enteiRaid1;
    User user2 = mock(User.class);
    String userName = "testUser2";
    when(user2.getName()).thenReturn(userName);
    LocalTime arrivalTime = nowTime.plusMinutes(30);
    RaidGroup group = new RaidGroup("testserver", "channel", "infoId", "emoteId", "userId",
            LocalDateTime.of(LocalDate.now(), arrivalTime));
    group = repo.newGroupForRaid(user2, group, enteiRaid, guild, config);
    List<RaidGroup> groupsForServer = repo.getGroupsForServer("testserver");
    assertThat(group != null, is(true));
    assertThat(groupsForServer.size(), is(1));
    assertThat(groupsForServer.iterator().next(), is(group));

    RaidGroup deleted = repo.deleteGroup(enteiRaid.getId(), group.getId());
    assertThat(deleted != null, is(true));
    groupsForServer = repo.getGroupsForServer("testserver");
    assertThat(groupsForServer.size(), is(0));
}
 
开发者ID:magnusmickelsson,项目名称:pokeraidbot,代码行数:39,代码来源:RaidRepositoryTest.java

示例9: testSignUp

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void testSignUp() throws Exception {
    clockService.setMockTime(LocalTime.of(10, 0)); // We're not allowed to create signups at night, so mocking time
    final LocalDateTime now = clockService.getCurrentDateTime();
    final LocalTime nowTime = now.toLocalTime();
    LocalDateTime endOfRaid = now.plusMinutes(45);
    final Gym gym = gymRepository.findByName("Blenda", uppsalaRegion);
    Raid enteiRaid = new Raid(pokemonRepository.search("Entei", null), endOfRaid, gym, localeService, uppsalaRegion);
    String raidCreatorName = "testUser1";
    User user = mock(User.class);
    when(user.getName()).thenReturn(raidCreatorName);
    Guild guild = mock(Guild.class);
    Config config = mock(Config.class);

    try {
        repo.newRaid(user, enteiRaid, guild, config, "test");
    } catch (RuntimeException e) {
        System.err.println(e.getMessage());
        fail("Could not save raid: " + e.getMessage());
    }
    User user2 = mock(User.class);
    String userName = "testUser2";
    when(user2.getName()).thenReturn(userName);
    Raid raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user2);
    enteiRaid.setId(raid.getId()); // Set to same id for equals comparison
    enteiRaid.setCreator(raid.getCreator()); // Set creator to same for equals comparison
    assertThat(raid, is(enteiRaid));
    int howManyPeople = 3;
    LocalTime arrivalTime = nowTime.plusMinutes(30);
    raid.signUp(user2, howManyPeople, arrivalTime, repo);
    assertThat(raid.getSignUps().size(), is(1));
    assertThat(raid.getNumberOfPeopleSignedUp(), is(howManyPeople));

    final Raid raidFromDb = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user2);
    assertThat(raidFromDb, is(raid));
    assertThat(raidFromDb.getSignUps().size(), is(1));
}
 
开发者ID:magnusmickelsson,项目名称:pokeraidbot,代码行数:38,代码来源:RaidRepositoryTest.java

示例10: changePokemonWorks

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void changePokemonWorks() throws Exception {
    clockService.setMockTime(LocalTime.of(10, 0)); // We're not allowed to create signups at night, so mocking time
    final LocalDateTime now = clockService.getCurrentDateTime();
    final LocalTime nowTime = now.toLocalTime();
    LocalDateTime endOfRaid = now.plusMinutes(45);
    final Gym gym = gymRepository.findByName("Blenda", uppsalaRegion);
    Raid enteiRaid = new Raid(pokemonRepository.search("Entei", null), endOfRaid, gym, localeService, uppsalaRegion);
    String raidCreatorName = "testUser1";
    User user = mock(User.class);
    Guild guild = mock(Guild.class);
    Config config = mock(Config.class);

    when(user.getName()).thenReturn(raidCreatorName);
    try {
        repo.newRaid(user, enteiRaid, guild, config, "test");
    } catch (RuntimeException e) {
        System.err.println(e.getMessage());
        fail("Could not save raid: " + e.getMessage());
    }

    Raid raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user);
    Raid changedRaid = repo.changePokemon(raid, pokemonRepository.search("Mewtwo", user), guild,
            config, user, "test");
    assertThat(raid.getEndOfRaid(), is(changedRaid.getEndOfRaid()));
    assertThat(raid.getGym(), is(changedRaid.getGym()));
    assertThat(raid.getSignUps(), is(changedRaid.getSignUps()));
    assertThat(raid.getRegion(), is(changedRaid.getRegion()));
    assertThat(raid.getPokemon().getName(), is("Entei"));
    assertThat(changedRaid.getPokemon().getName(), is("Mewtwo"));
}
 
开发者ID:magnusmickelsson,项目名称:pokeraidbot,代码行数:32,代码来源:RaidRepositoryTest.java

示例11: changeEndOfRaidWorks

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void changeEndOfRaidWorks() throws Exception {
    clockService.setMockTime(LocalTime.of(10, 0)); // We're not allowed to create signups at night, so mocking time
    final LocalDateTime now = clockService.getCurrentDateTime();
    final LocalTime nowTime = now.toLocalTime();
    LocalDateTime endOfRaid = now.plusMinutes(45);
    final Gym gym = gymRepository.findByName("Blenda", uppsalaRegion);
    Raid enteiRaid = new Raid(pokemonRepository.search("Entei", null), endOfRaid, gym, localeService, uppsalaRegion);
    String raidCreatorName = "testUser1";
    User user = mock(User.class);
    when(user.getName()).thenReturn(raidCreatorName);
    Guild guild = mock(Guild.class);
    Config config = mock(Config.class);

    try {
        repo.newRaid(user, enteiRaid, guild, config, "test");
    } catch (RuntimeException e) {
        System.err.println(e.getMessage());
        fail("Could not save raid: " + e.getMessage());
    }

    Raid raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user);
    Raid changedRaid = repo.changeEndOfRaid(raid.getId(), endOfRaid.plusMinutes(5), guild, config, user, "test");
    assertThat(raid.getEndOfRaid(), not(changedRaid.getEndOfRaid()));
    assertThat(changedRaid.getEndOfRaid(), is(raid.getEndOfRaid().plusMinutes(5)));
    assertThat(raid.getGym(), is(changedRaid.getGym()));
    assertThat(raid.getSignUps(), is(changedRaid.getSignUps()));
    assertThat(raid.getRegion(), is(changedRaid.getRegion()));
    assertThat(raid.getPokemon().getName(), is(changedRaid.getPokemon().getName()));
}
 
开发者ID:magnusmickelsson,项目名称:pokeraidbot,代码行数:31,代码来源:RaidRepositoryTest.java

示例12: convert

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Override
public LocalTime convert(LocalDateTime source) {
	return source.toLocalTime();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:DateTimeConverters.java

示例13: 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:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:78,代码来源:JavatimeTest.java

示例14: 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

示例15: withStartDateTime

import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
 * Returns a new interval based on this interval but with a different start date
 * and time.
 *
 * @param dateTime the new start date and time
 * @return a new interval
 */
public Interval withStartDateTime(LocalDateTime dateTime) {
    requireNonNull(dateTime);
    return new Interval(dateTime.toLocalDate(), dateTime.toLocalTime(), endDate, endTime);
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:12,代码来源:Interval.java


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