當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalDateTime類代碼示例

本文整理匯總了Java中java.time.LocalDateTime的典型用法代碼示例。如果您正苦於以下問題:Java LocalDateTime類的具體用法?Java LocalDateTime怎麽用?Java LocalDateTime使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LocalDateTime類屬於java.time包,在下文中一共展示了LocalDateTime類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setTimeout

import java.time.LocalDateTime; //導入依賴的package包/類
public void setTimeout(String id, LocalDateTime to)
{
    try(Connection conn = botico.sql.connect())
    {
        try(PreparedStatement st = conn.prepareStatement("INSERT OR REPLACE INTO `timeouts` (`id`, `expiresIn`) VALUES(?, ?);"))
        {
            st.setString(1, id);
            st.setTimestamp(2, Timestamp.valueOf(to));
            st.executeUpdate();
        }
    }
    catch (SQLException e)
    {
        botico.log.error("Can't set timeout!", e);
    }
}
 
開發者ID:PearXTeam,項目名稱:Botico2,代碼行數:17,代碼來源:BTimeoutManager.java

示例2: canAccept

import java.time.LocalDateTime; //導入依賴的package包/類
@Override
public boolean canAccept(final Class<?> type) {
	return LocalDateTime.class.equals(type)
			|| OffsetDateTime.class.equals(type)
			|| ZonedDateTime.class.equals(type)
			|| LocalDate.class.equals(type)
			|| LocalTime.class.equals(type)
			|| OffsetTime.class.equals(type)
			|| Year.class.equals(type)
			|| YearMonth.class.equals(type)
			|| MonthDay.class.equals(type)
			|| Month.class.equals(type)
			|| DayOfWeek.class.equals(type)
			|| checkEra(type)
			|| checkChronoLocalDate(type);
}
 
開發者ID:future-architect,項目名稱:uroborosql,代碼行數:17,代碼來源:DateTimeApiPropertyMapper.java

示例3: getPost

import java.time.LocalDateTime; //導入依賴的package包/類
public static Node getPost(Node author, Long time) {
    LocalDateTime postedDateTime = LocalDateTime.ofEpochSecond(time, 0, ZoneOffset.UTC);
    RelationshipType original = RelationshipType.withName("POSTED_ON_" +
            postedDateTime.format(dateFormatter));
    Node post = null;
    for(Relationship r1 : author.getRelationships(Direction.OUTGOING, original)) {
        Node potential = r1.getEndNode();
        if (time.equals(potential.getProperty(TIME))) {
            post = potential;
            break;
        }
    }
    if(post == null) { throw PostExceptions.postNotFound; };

    return post;
}
 
開發者ID:maxdemarzi,項目名稱:grittier_ext,代碼行數:17,代碼來源:Users.java

示例4: assertCreateRaidTimeNotBeforeNow

import java.time.LocalDateTime; //導入依賴的package包/類
public static void assertCreateRaidTimeNotBeforeNow(User user, LocalDateTime dateAndTime,
                                                    LocaleService localeService) {
    final LocalDateTime now = clockService.getCurrentDateTime();
    if (dateAndTime.isBefore(now)) {
        throw new UserMessedUpException(user,
                localeService.getMessageFor(LocaleService.TIMEZONE, localeService.getLocaleForUser(user),
                        printTimeIfSameDay(dateAndTime), printTimeIfSameDay(now)));
    }
}
 
開發者ID:magnusmickelsson,項目名稱:pokeraidbot,代碼行數:10,代碼來源:Utils.java

示例5: test_plusHours_fromZero

import java.time.LocalDateTime; //導入依賴的package包/類
@Test
public void test_plusHours_fromZero() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = base.toLocalDate().minusDays(3);
    LocalTime t = LocalTime.of(21, 0);

    for (int i = -50; i < 50; i++) {
        LocalDateTime dt = base.plusHours(i);
        t = t.plusHours(1);

        if (t.getHour() == 0) {
            d = d.plusDays(1);
        }

        assertEquals(dt.toLocalDate(), d);
        assertEquals(dt.toLocalTime(), t);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:TCKLocalDateTime.java

示例6: addUser

import java.time.LocalDateTime; //導入依賴的package包/類
@Test
public void addUser() {
    User user = new User();
    user.setUserName("goodsave");
    user.setPassWord(passwordEncoder.encode("goodsave"));
    user.setEmail("[email protected]");
    user.setFace(null);
    user.setLastLoginTime(LocalDateTime.now());
    user.setPhone("15505090507");
    user.setRegisterIp("192.168.1.1");
    user.setLastLoginIp("192.168.1.1");
    user.setRegisterTime(LocalDateTime.now());
    user.setSignature("hi goodsave");
    user.setState(UserState.NORMAL);
    user.setUserNick("xiaochun");
    user.setGroups(groupRepository.findAll());
    userRepository.saveAndFlush(user);
}
 
開發者ID:MinsxCloud,項目名稱:minsx-framework,代碼行數:19,代碼來源:AddTest.java

示例7: test_NewYork_getOffsetInfo_overlap

import java.time.LocalDateTime; //導入依賴的package包/類
public void test_NewYork_getOffsetInfo_overlap() {
    ZoneRules test = americaNewYork();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 11, 2, 1, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, ZoneOffset.ofHours(-4), OVERLAP);
    assertEquals(trans.isGap(), false);
    assertEquals(trans.isOverlap(), true);
    assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(-4));
    assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(-5));
    assertEquals(trans.getInstant(), createInstant(2008, 11, 2, 2, 0, ZoneOffset.ofHours(-4)));
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-1)), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-5)), true);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-4)), true);
    assertEquals(trans.isValidOffset(OFFSET_PTWO), false);
    assertEquals(trans.toString(), "Transition[Overlap at 2008-11-02T02:00-04:00 to -05:00]");

    assertFalse(trans.equals(null));
    assertFalse(trans.equals(ZoneOffset.ofHours(-4)));
    assertTrue(trans.equals(trans));

    final ZoneOffsetTransition otherTrans = test.getTransition(dateTime);
    assertTrue(trans.equals(otherTrans));
    assertEquals(trans.hashCode(), otherTrans.hashCode());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:24,代碼來源:TCKZoneRules.java

示例8: findAllExistsInfos

import java.time.LocalDateTime; //導入依賴的package包/類
@NotNull
public List<InfoSchema> findAllExistsInfos() {
    try (ResultSet rs = this.findAllExistsInfoStatement.executeQuery()) {
        List<InfoSchema> list = new ArrayList<>();
        while (rs.next()) {
            list.add(new InfoSchema.Builder(
                    rs.getString("id"),
                    rs.getInt("is_sanma") == 1,
                    rs.getInt("is_tonnan") == 1,
                    LocalDateTime.from(DateTimeFormatter.ISO_LOCAL_DATE_TIME.parse(rs.getString("date_time"))),
                    rs.getString("first"),
                    rs.getString("second"),
                    rs.getString("third"),
                    rs.getString("fourth")
            ).build());
        }
        return list;
    } catch (SQLException e) {
        throw new RuntimeException();
    }
}
 
開發者ID:CrazyBBB,項目名稱:tenhou-visualizer,代碼行數:22,代碼來源:DatabaseService.java

示例9: processWebDriverLogs

import java.time.LocalDateTime; //導入依賴的package包/類
private void processWebDriverLogs(WebDriver webDriver) {
    Logs logs = webDriver.manage().logs();
    for (String logType : WEBDRIVER_LOG_LEVELS.keySet()) {
        LOGGER.info("Dumping webdriver log for log type " + logType);
        LogEntries logEntries = logs.get(logType);
        for (LogEntry logEntry : logEntries) {
            String formattedOriginalTimestamp = LOG_TIMESTAMP_FORMAT
                    .format(LocalDateTime.ofInstant(Instant.ofEpochMilli(logEntry.getTimestamp()), ZoneOffset.UTC));
            Level logEntryLevel = logEntry.getLevel();
            if (logEntryLevel.equals(Level.FINE)) {
                LOGGER.debug(MESSAGE_PATTERN, logType, formattedOriginalTimestamp, logEntry.getMessage());
            } else if (logEntryLevel.equals(Level.INFO)) {
                LOGGER.info(MESSAGE_PATTERN, logType, formattedOriginalTimestamp, logEntry.getMessage());
            } else if (logEntryLevel.equals(Level.WARNING)) {
                LOGGER.warn(MESSAGE_PATTERN, logType, formattedOriginalTimestamp, logEntry.getMessage());
            } else if (logEntryLevel.equals(Level.SEVERE)) {
                LOGGER.error(MESSAGE_PATTERN, logType, formattedOriginalTimestamp, logEntry.getMessage());
            } else if (logEntryLevel.equals(Level.FINER)) {
                LOGGER.trace(MESSAGE_PATTERN, logType, formattedOriginalTimestamp, logEntry.getMessage());
            }
        }
    }
}
 
開發者ID:willhaben,項目名稱:willtest,代碼行數:24,代碼來源:WebDriverLog.java

示例10: data_formatNonGenericTimeZonePatterns_2

import java.time.LocalDateTime; //導入依賴的package包/類
@DataProvider(name = "formatNonGenericTimeZonePatterns_2")
Object[][]  data_formatNonGenericTimeZonePatterns_2() {
    return new Object[][] {
            {"yyyy-MM-dd HH:mm:ss z", LocalDateTime.of(2015, Month.NOVEMBER, 1, 0, 30),
             "2015-11-01 00:30:00 PDT"},
            {"yyyy-MM-dd HH:mm:ss z", LocalDateTime.of(2015, Month.NOVEMBER, 1, 1, 30),
             "2015-11-01 01:30:00 PT"},
            {"yyyy-MM-dd HH:mm:ss z", LocalDateTime.of(2015, Month.NOVEMBER, 1, 2, 30),
             "2015-11-01 02:30:00 PST"},
            {"yyyy-MM-dd HH:mm:ss zzzz", LocalDateTime.of(2015, Month.NOVEMBER, 1, 0, 30),
             "2015-11-01 00:30:00 Pacific Daylight Time"},
            {"yyyy-MM-dd HH:mm:ss zzzz", LocalDateTime.of(2015, Month.NOVEMBER, 1, 1, 30),
             "2015-11-01 01:30:00 Pacific Time"},
            {"yyyy-MM-dd HH:mm:ss zzzz", LocalDateTime.of(2015, Month.NOVEMBER, 1, 2, 30),
             "2015-11-01 02:30:00 Pacific Standard Time"},
    };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:TCKDateTimeFormatterBuilder.java

示例11: create

import java.time.LocalDateTime; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public <K> Index<K> create(Class<K> keyType, int initialSize) {
    switch (ArrayType.of(keyType)) {
        case INTEGER:           return (Index<K>)new IndexOfInts(initialSize);
        case LONG:              return (Index<K>)new IndexOfLongs(initialSize);
        case DOUBLE:            return (Index<K>)new IndexOfDoubles(initialSize);
        case STRING:            return (Index<K>)new IndexOfStrings(initialSize);
        case YEAR:              return (Index<K>)new IndexWithIntCoding<>((Class<Year>)keyType, yearCoding, initialSize);
        case DATE:              return (Index<K>)new IndexWithLongCoding<>((Class<Date>)keyType, dateCoding, initialSize);
        case INSTANT:           return (Index<K>)new IndexWithLongCoding<>((Class<Instant>)keyType, instantCoding, initialSize);
        case LOCAL_DATE:        return (Index<K>)new IndexWithLongCoding<>((Class<LocalDate>)keyType, localDateCoding, initialSize);
        case LOCAL_TIME:        return (Index<K>)new IndexWithLongCoding<>((Class<LocalTime>)keyType, localTimeCoding, initialSize);
        case LOCAL_DATETIME:    return (Index<K>)new IndexWithLongCoding<>((Class<LocalDateTime>)keyType, localDateTimeCoding, initialSize);
        case ZONED_DATETIME:    return (Index<K>)new IndexWithLongCoding<>((Class<ZonedDateTime>)keyType, zonedDateTimeCoding, initialSize);
        default:                return new IndexOfObjects<>(keyType, initialSize);
    }
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:19,代碼來源:IndexFactoryDefault.java

示例12: testClaimsAndVerifyHmac

import java.time.LocalDateTime; //導入依賴的package包/類
@Test
public void testClaimsAndVerifyHmac() throws Exception {
    token = JWT.create()
            .withArrayClaim("roles", new String[]{"Role1", "Role2"})
            .withClaim("uid", 1)
            .withClaim("name", "admin")
            .withClaim("url", "http://test.com")
            .withIssuedAt(Date.from(LocalDateTime.now().toInstant(offset)))
            .withExpiresAt(Date.from(LocalDateTime.now().plusHours(2).toInstant(offset)))
            .sign(Algorithm.HMAC256("secret"));

    final Verifier verifier = Verifier.create(token);
    assertEquals(1, verifier.getUid());
    assertEquals("admin", verifier.getName());
    assertEquals("http://test.com", verifier.getUrl());
    final List<String> roles = verifier.getRoles();
    assertEquals(2, roles.size());
    assertEquals("Role1", roles.get(0));
    assertEquals("Role2", roles.get(1));

    assertTrue(verifier.verify(Algorithm.HMAC256("secret")));
    assertFalse(verifier.verify(Algorithm.HMAC256("wrong secret")));
}
 
開發者ID:Islandora-CLAW,項目名稱:Syn,代碼行數:24,代碼來源:VerifierTest.java

示例13: RaceDetails

import java.time.LocalDateTime; //導入依賴的package包/類
private RaceDetails(long ID) {
    id = ID;
    odds = new HashMap<>();
    raceTime = LocalDateTime.MIN;
    version = 1;
    winner = Optional.empty();
}
 
開發者ID:hazelcast,項目名稱:betleopard,代碼行數:8,代碼來源:Race.java

示例14: test_getters_overlap

import java.time.LocalDateTime; //導入依賴的package包/類
@Test
public void test_getters_overlap() throws Exception {
    LocalDateTime before = LocalDateTime.of(2010, 10, 31, 1, 0);
    LocalDateTime after = LocalDateTime.of(2010, 10, 31, 0, 0);
    ZoneOffsetTransition test = ZoneOffsetTransition.of(before, OFFSET_0300, OFFSET_0200);
    assertEquals(test.isGap(), false);
    assertEquals(test.isOverlap(), true);
    assertEquals(test.getDateTimeBefore(), before);
    assertEquals(test.getDateTimeAfter(), after);
    assertEquals(test.getInstant(), before.toInstant(OFFSET_0300));
    assertEquals(test.getOffsetBefore(), OFFSET_0300);
    assertEquals(test.getOffsetAfter(), OFFSET_0200);
    assertEquals(test.getDuration(), Duration.of(-1, HOURS));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:15,代碼來源:TCKZoneOffsetTransition.java

示例15: getBaseEntityValueAsLocalDateTime

import java.time.LocalDateTime; //導入依賴的package包/類
public LocalDateTime getBaseEntityValueAsLocalDateTime(final String baseEntityCode, final String attributeCode) {
	BaseEntity be = getBaseEntityByCode(baseEntityCode);
	Optional<EntityAttribute> ea = be.findEntityAttribute(attributeCode);
	if (ea.isPresent()) {
		return ea.get().getValueDateTime();
	} else {
		return null;
	}
}
 
開發者ID:genny-project,項目名稱:rulesservice,代碼行數:10,代碼來源:QRules.java


注:本文中的java.time.LocalDateTime類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。