本文整理汇总了Java中java.time.LocalDateTime.plusNanos方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.plusNanos方法的具体用法?Java LocalDateTime.plusNanos怎么用?Java LocalDateTime.plusNanos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDateTime
的用法示例。
在下文中一共展示了LocalDateTime.plusNanos方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateLogRecords
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static LogfileSummary generateLogRecords(LogfileType type, LocalDateTime start, LocalDateTime end, Consumer<String> consumer) {
LogfileSummary summary = new LogfileSummary();
LocalDateTime next = start;
while (next.isBefore(end)) {
consumer.accept(createLogEntry(type, next, summary));
next = next.plusNanos(5000000L);
}
return summary;
}
示例2: 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);
}
}
示例3: test_plusNanos_fromZero
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="plusNanos_fromZero")
public void test_plusNanos_fromZero(long nanoseconds, LocalDate date, int hour, int min, int sec, int nanos) {
LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
LocalDateTime t = base.plusNanos(nanoseconds);
assertEquals(date, t.toLocalDate());
assertEquals(hour, t.getHour());
assertEquals(min, t.getMinute());
assertEquals(sec, t.getSecond());
assertEquals(nanos, t.getNano());
}
示例4: 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);
}