本文整理汇总了Java中java.time.Instant.atOffset方法的典型用法代码示例。如果您正苦于以下问题:Java Instant.atOffset方法的具体用法?Java Instant.atOffset怎么用?Java Instant.atOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.Instant
的用法示例。
在下文中一共展示了Instant.atOffset方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreate
import java.time.Instant; //导入方法依赖的package包/类
/**
* 初始化
*/
@Test
public void testCreate() {
// 此时获取的是 UTC时区的时间,北京时间需要加上偏移量
Instant instant = Instant.now();
System.out.println(instant);
// 偏移8个小时,东八区
OffsetDateTime dateTime = instant.atOffset(ZoneOffset.ofHours(8));
System.out.println(dateTime);
// 相对1970-1-1 00:00:00,向后偏移1000000毫秒
Instant instantMilli = Instant.ofEpochMilli(1000000);
System.out.println(instantMilli);
// 相对1970-1-1 00:00:00,向后偏移60秒
Instant instantSecond = Instant.ofEpochSecond(60);
System.out.println(instantSecond);
}
示例2: test_atOffset
import java.time.Instant; //导入方法依赖的package包/类
@Test
public void test_atOffset() {
for (int i = 0; i < (24 * 60 * 60); i++) {
Instant instant = Instant.ofEpochSecond(i);
OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1));
assertEquals(test.getYear(), 1970);
assertEquals(test.getMonthValue(), 1);
assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0));
assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24);
assertEquals(test.getMinute(), (i / 60) % 60);
assertEquals(test.getSecond(), i % 60);
}
}
示例3: instantOfNextFrame
import java.time.Instant; //导入方法依赖的package包/类
@Override
public Instant instantOfNextFrame(final Instant current) {
final OffsetDateTime time = current.atOffset(UTC);
final int minutes = time.get(MINUTE_OF_HOUR);
return time.withSecond(0).withNano(0).plusMinutes(30 - (minutes % 30)).toInstant();
}
示例4: instantOfNextFrame
import java.time.Instant; //导入方法依赖的package包/类
@Override
public Instant instantOfNextFrame(final Instant current) {
final OffsetDateTime time = current.atOffset(UTC);
final int minutes = time.get(MINUTE_OF_HOUR);
return time.withSecond(0).withNano(0).plusMinutes(5 - (minutes % 5)).toInstant();
}
示例5: instantOfNextFrame
import java.time.Instant; //导入方法依赖的package包/类
@Override
public Instant instantOfNextFrame(final Instant current) {
final OffsetDateTime time = current.atOffset(UTC);
final int minutes = time.get(MINUTE_OF_HOUR);
return time.withSecond(0).withNano(0).plusMinutes(15 - (minutes % 15)).toInstant();
}
示例6: instantOfNextFrame
import java.time.Instant; //导入方法依赖的package包/类
@Override
public Instant instantOfNextFrame(final Instant current) {
final OffsetDateTime time = current.atOffset(UTC);
return time.withSecond(0).withNano(0).withMinute(0).plusHours(1).toInstant();
}