本文整理汇总了Java中java.time.LocalDateTime.now方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.now方法的具体用法?Java LocalDateTime.now怎么用?Java LocalDateTime.now使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDateTime
的用法示例。
在下文中一共展示了LocalDateTime.now方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static void main(String[] args) {
final LocalDateTime start = LocalDateTime.now();
final Array<LocalDateTime> rowKeys = Range.of(start, start.plusSeconds(10000000), Duration.ofSeconds(1)).toArray().shuffle(1);
final Array<String> colKeys = Array.of("A", "B", "C", "D");
final DataFrame<LocalDateTime,String> frame = DataFrame.ofDoubles(rowKeys, colKeys).applyDoubles(v -> Math.random());
for (int i=0; i<20; ++i) {
frame.applyDoubles(v -> Math.random());
final MyComparator comp = new MyComparator();
final long t1 = System.nanoTime();
//frame.rows().parallel().sort(true);
frame.rows().parallel().sort(true);
//frame.rows().parallel().sort(true, "A");
final long t2 = System.nanoTime();
System.out.println("Sorted DataFrame in " + ((t2-t1)/1000000) + " millis");
}
}
示例2: intercept
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
Object record = invocation.getArgs()[1];
if (record instanceof TimeTraceable) {
TimeTraceable timeTraceableRecord = (TimeTraceable) record;
LocalDateTime now = LocalDateTime.now();
if (mappedStatement.getSqlCommandType().equals(SqlCommandType.INSERT)) {
timeTraceableRecord.setCreateTime(now);
}
timeTraceableRecord.setUpdateTime(now);
} else if (record instanceof TimestampTraceable) {
TimestampTraceable timestampTraceableRecord = (TimestampTraceable) record;
long timestamp = Instant.now().getEpochSecond();
if (mappedStatement.getSqlCommandType().equals(SqlCommandType.INSERT)) {
timestampTraceableRecord.setCreateTime(timestamp);
}
timestampTraceableRecord.setUpdateTime(timestamp);
}
return invocation.proceed();
}
示例3: timeInRaidspan
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void timeInRaidspan() throws Exception {
User user = mock(User.class);
when(user.getName()).thenReturn("User");
LocalDateTime localDateTime = LocalDateTime.now();
LocalDateTime same = localDateTime;
LocalDateTime before = localDateTime.minusMinutes(1);
LocalDateTime after = localDateTime.plusMinutes(1);
LocalDateTime end = localDateTime.plusMinutes(Utils.RAID_DURATION_IN_MINUTES);
LocalDateTime sameAsEnd = end;
LocalDateTime beforeEnd = end.minusMinutes(1);
LocalDateTime afterEnd = end.plusMinutes(1);
final LocaleService localeService = mock(LocaleService.class);
when(localeService.getMessageFor(any(), any(), any())).thenReturn("Mupp");
Raid raid = new Raid(pokemonRepository.getByName("Tyranitar"), end,
new Gym("Test", "id", "10", "10", null),
localeService, "Test");
checkWhetherAssertFails(user, same, localeService, raid, false);
checkWhetherAssertFails(user, after, localeService, raid, false);
checkWhetherAssertFails(user, before, localeService, raid, true);
checkWhetherAssertFails(user, sameAsEnd, localeService, raid, false);
checkWhetherAssertFails(user, afterEnd, localeService, raid, true);
checkWhetherAssertFails(user, beforeEnd, localeService, raid, false);
}
示例4: formatLocalName
import java.time.LocalDateTime; //导入方法依赖的package包/类
@SideOnly(Side.CLIENT)
public String formatLocalName(Component sub) {
LocalDateTime time = LocalDateTime.now();
if(time.getMonth() == Month.APRIL && time.getDayOfMonth() == 1) {
return "April Fools!";
}
String format = I18n.format(RandoresKeys.FORMAT);
String name = this.getName();
String compName = sub.getLocalName();
return format.replace("${name}", name).replace("${item}", compName);
}
示例5: testIfOverdue
import java.time.LocalDateTime; //导入方法依赖的package包/类
public void testIfOverdue(TestService testService, EventPublisher eventPublisher) {
if (testService == null) {
throw new IllegalArgumentException(("TestService must be set."));
}
TestResult lastTestResult = testResults.peek();
if (lastTestResult == null) {
this.test(testService, eventPublisher);
} else {
LocalDateTime now = LocalDateTime.now();
LocalDateTime targetTime = lastTestResult.dateTime().plus(interval.toMillis(), ChronoUnit.MILLIS);
if (targetTime.isBefore(now)) {
this.test(testService, eventPublisher);
}
}
}
示例6: ProcessModelImpl
import java.time.LocalDateTime; //导入方法依赖的package包/类
ProcessModelImpl(final String name, final String description, final ProcessModelState state,
final List<SubjectModelImpl> subjectModels, final SubjectModelImpl starterSubject,
final float version) {
this.name = name;
this.description = description;
this.createdAt = LocalDateTime.now();
this.state = state;
this.subjectModels = subjectModels;
this.starterSubject = starterSubject;
this.version = version;
}
示例7: starting
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Override
protected void starting(Description description) {
LocalDateTime now = LocalDateTime.now();
time.set(now.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
System.out.println("#######################################");
System.out.println("# Starting: " + description.getDisplayName() + " [start-time=" + TIMESTAMP_FORMAT.format(now) + ']');
System.out.println("#--------------------------------------");
}
示例8: createApplicationHistory
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static DrinkWaterApplicationHistory createApplicationHistory(DrinkWaterApplication app) {
try {
CustomJacksonObjectMapper mapper = new CustomJacksonObjectMapper();
String config = mapper.writeValueAsString(app.configuration().getConfigurations());
return new DrinkWaterApplicationHistory(LocalDateTime.now(), config, "noInfoNow");
} catch (Exception e) {
throw new RuntimeException("exception while serializing : be carrefull with MOCK objects, it can lead to infinite loops", e);
}
}
示例9: testParallelStream
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* 使用并行流
* channel=127, sum amount=2999937
* channel=128, sum amount=2999940
* channel=129, sum amount=2999940
* channel=130, sum amount=2999940
* channel=131, sum amount=2999940
* cost time:440
*/
@Test
public void testParallelStream() {
List<Order> list = Lists.newArrayList();
for (int i = 0; i < size; i++) {
Order o = new Order(i, "success", 3, i % 5 + 127, "12112121223", "jim", "18612534462", LocalDateTime.now().minusDays(12), LocalDateTime.now());
list.add(o);
}
Instant start = Instant.now();
list.parallelStream().collect(Collectors.groupingBy(Order::getChannelId)).entrySet()
.parallelStream()
.collect(Collectors.toMap(Map.Entry::getKey, element -> element.getValue()
.parallelStream()
.filter(order -> order.getOrderId() > 100)
.filter(order -> order.getUserName().equals("jim"))
.collect(Collectors.summingLong(Order::getAmount))))
.entrySet()
.forEach(data -> {
System.out.println("channel=" + data.getKey() + ", sum amount=" + data.getValue());
});
Instant end = Instant.now();
long millis = Duration.between(start, end).toMillis();
System.out.println("cost time:" + millis);
}
示例10: Quiz
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
*
* @param quizTitle
* @param topic
* @param questions
* @param creatorId
* @param maxScore
*/
public Quiz(String quizTitle, String topic, List<QuizQuestion> questions,
String creatorId, int maxScore) {
super();
this.quizTitle = quizTitle;
this.topic = topic;
this.questions = questions;
this.creatorId = creatorId;
this.createdOn = LocalDateTime.now();
this.maxScore = maxScore;
}
示例11: getPicturesSince
import java.time.LocalDateTime; //导入方法依赖的package包/类
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public List<String> getPicturesSince(){
final LocalDateTime now = LocalDateTime.now();
final List<String> times = Arrays.asList(String.valueOf(now));
return times;
}
示例12: dateTimeNow
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static String dateTimeNow() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime dateTime = LocalDateTime.now();
String formattedDateTime = dateTime.format(formatter) + ": ";
return formattedDateTime;
}
示例13: isAprilFools
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static boolean isAprilFools() {
LocalDateTime now = LocalDateTime.now();
return now.getDayOfMonth()==1 && now.getMonth()==Month.APRIL;
}
示例14: ReceiveSubmission
import java.time.LocalDateTime; //导入方法依赖的package包/类
ReceiveSubmission() {
this.submissionState = SubmissionState.TO_RECEIVE;
this.createdAt = LocalDateTime.now();
}
示例15: testClacPlus
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* 时间运算,计算完成后会返回新的对象,并不会改变原来的时间
*/
@Test
public void testClacPlus() {
LocalDateTime ldt = LocalDateTime.now();
System.out.println(ldt);
// 加: 天
LocalDateTime day = ldt.plusDays(1);
System.out.println("day: " + day);
// 加: 小时
LocalDateTime hours = ldt.plusHours(1);
System.out.println("hours: " + hours);
// 加: 分钟
LocalDateTime minutes = ldt.plusMinutes(1);
System.out.println("minutes: " + minutes);
// 加: 月
LocalDateTime months = ldt.plusMonths(1);
System.out.println("months: " + months);
// 加: 纳秒
LocalDateTime nanos = ldt.plusNanos(1);
System.out.println("nanos: " + nanos);
// 加: 秒
LocalDateTime seconds = ldt.plusSeconds(1);
System.out.println("seconds: " + seconds);
// 加: 周
LocalDateTime weeks = ldt.plusWeeks(1);
System.out.println("weeks: " + weeks);
// 加: 年
LocalDateTime years = ldt.plusYears(1);
System.out.println("years: " + years);
System.out.println(ldt);
}