本文整理汇总了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);
}
}
示例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);
}
示例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;
}
示例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)));
}
}
示例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);
}
}
示例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);
}
示例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());
}
示例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();
}
}
示例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());
}
}
}
}
示例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"},
};
}
示例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);
}
}
示例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")));
}
示例13: RaceDetails
import java.time.LocalDateTime; //导入依赖的package包/类
private RaceDetails(long ID) {
id = ID;
odds = new HashMap<>();
raceTime = LocalDateTime.MIN;
version = 1;
winner = Optional.empty();
}
示例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));
}
示例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;
}
}