本文整理汇总了Java中java.time.OffsetDateTime.ofInstant方法的典型用法代码示例。如果您正苦于以下问题:Java OffsetDateTime.ofInstant方法的具体用法?Java OffsetDateTime.ofInstant怎么用?Java OffsetDateTime.ofInstant使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.OffsetDateTime
的用法示例。
在下文中一共展示了OffsetDateTime.ofInstant方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTest_factory_ofInstant_all
import java.time.OffsetDateTime; //导入方法依赖的package包/类
private void doTest_factory_ofInstant_all(long minYear, long maxYear) {
long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
int minOffset = (minYear <= 0 ? 0 : 3);
int maxOffset = (maxYear <= 0 ? 0 : 3);
long minDays = (minYear * 365L + ((minYear + minOffset) / 4L - (minYear + minOffset) / 100L + (minYear + minOffset) / 400L)) - days_0000_to_1970;
long maxDays = (maxYear * 365L + ((maxYear + maxOffset) / 4L - (maxYear + maxOffset) / 100L + (maxYear + maxOffset) / 400L)) + 365L - days_0000_to_1970;
final LocalDate maxDate = LocalDate.of(Year.MAX_VALUE, 12, 31);
OffsetDateTime expected = OffsetDateTime.of(LocalDate.of((int) minYear, 1, 1), LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC);
for (long i = minDays; i < maxDays; i++) {
Instant instant = Instant.ofEpochSecond(i * 24L * 60L * 60L);
try {
OffsetDateTime test = OffsetDateTime.ofInstant(instant, ZoneOffset.UTC);
assertEquals(test, expected);
if (expected.toLocalDate().equals(maxDate) == false) {
expected = expected.plusDays(1);
}
} catch (RuntimeException|Error ex) {
System.out.println("Error: " + i + " " + expected);
throw ex;
}
}
}
示例2: getCreatedTime
import java.time.OffsetDateTime; //导入方法依赖的package包/类
/**
* Get the created time of this snowflake object.
*
* @return The created time.
*/
default OffsetDateTime getCreatedTime() {
long id = Long.parseLong(getId());
// Get the first 22 digits
id = id >> 22;
// Add Discord Epoch time, which is the first second of 2015
id += 1420070400000L;
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(id), ZoneId.systemDefault());
}
示例3: factory_ofInstant_tooBig
import java.time.OffsetDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofInstant_tooBig() {
long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
long year = Year.MAX_VALUE + 1L;
long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L);
OffsetDateTime.ofInstant(instant, ZoneOffset.UTC);
}
示例4: factory_ofInstant_maxWithMaxOffset
import java.time.OffsetDateTime; //导入方法依赖的package包/类
public void factory_ofInstant_maxWithMaxOffset() {
long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
int year = Year.MAX_VALUE;
long days = (year * 365L + (year / 4 - year / 100 + year / 400)) + 365 - days_0000_to_1970;
Instant instant = Instant.ofEpochSecond((days + 1) * 24L * 60L * 60L - 1 - OFFSET_MAX.getTotalSeconds());
OffsetDateTime test = OffsetDateTime.ofInstant(instant, OFFSET_MAX);
assertEquals(test.getYear(), Year.MAX_VALUE);
assertEquals(test.getMonth().getValue(), 12);
assertEquals(test.getDayOfMonth(), 31);
assertEquals(test.getOffset(), OFFSET_MAX);
assertEquals(test.getHour(), 23);
assertEquals(test.getMinute(), 59);
assertEquals(test.getSecond(), 59);
assertEquals(test.getNano(), 0);
}
示例5: hasExpired
import java.time.OffsetDateTime; //导入方法依赖的package包/类
public boolean hasExpired() {
OffsetDateTime expirationDateTime = OffsetDateTime.ofInstant(
Instant.ofEpochSecond(expirationTime), ZoneId.systemDefault());
OffsetDateTime now = OffsetDateTime.now(ZoneId.systemDefault());
return now.isAfter(expirationDateTime);
}
示例6: insertBuild
import java.time.OffsetDateTime; //导入方法依赖的package包/类
public static long insertBuild(Build build) {
LOGGER.debug("Inserting build {} into the database.", build.getBuildId());
Object start;
Object finish;
if (SqlHelper.isMySql()) {
start = LocalDateTime.ofInstant(build.getTimer().getStartTime(), ZoneOffset.UTC);
finish = LocalDateTime.ofInstant(build.getTimer().getFinishTime(), ZoneOffset.UTC);
} else {
start = OffsetDateTime.ofInstant(build.getTimer().getStartTime(), ZoneId.of(build.getTimer().getTimeZoneId()));
finish = OffsetDateTime.ofInstant(build.getTimer().getFinishTime(), ZoneId.of(build.getTimer().getTimeZoneId()));
}
Object[] params = new Object[]{
build.getBuildId(),
build.getUserName(),
build.getRootProjectName(),
start,
finish,
build.getStatus(),
build.getTagsAsSingleString()
};
Long generatedId = Yank.insertSQLKey("INSERT_BUILD", params);
if (generatedId == 0) {
throw new RuntimeException("Unable to save build record for " + build.getBuildId());
}
return generatedId;
}
示例7: factory_ofInstant_allDaysInCycle
import java.time.OffsetDateTime; //导入方法依赖的package包/类
public void factory_ofInstant_allDaysInCycle() {
// sanity check using different algorithm
OffsetDateTime expected = OffsetDateTime.of(LocalDate.of(1970, 1, 1), LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC);
for (long i = 0; i < 146097; i++) {
Instant instant = Instant.ofEpochSecond(i * 24L * 60L * 60L);
OffsetDateTime test = OffsetDateTime.ofInstant(instant, ZoneOffset.UTC);
assertEquals(test, expected);
expected = expected.plusDays(1);
}
}
示例8: factory_ofInstant_tooLow
import java.time.OffsetDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofInstant_tooLow() {
long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
int year = Year.MIN_VALUE - 1;
long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L);
OffsetDateTime.ofInstant(instant, ZoneOffset.UTC);
}
示例9: factory_ofInstant_minWithMinOffset
import java.time.OffsetDateTime; //导入方法依赖的package包/类
public void factory_ofInstant_minWithMinOffset() {
long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
int year = Year.MIN_VALUE;
long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L - OFFSET_MIN.getTotalSeconds());
OffsetDateTime test = OffsetDateTime.ofInstant(instant, OFFSET_MIN);
assertEquals(test.getYear(), Year.MIN_VALUE);
assertEquals(test.getMonth().getValue(), 1);
assertEquals(test.getDayOfMonth(), 1);
assertEquals(test.getOffset(), OFFSET_MIN);
assertEquals(test.getHour(), 0);
assertEquals(test.getMinute(), 0);
assertEquals(test.getSecond(), 0);
assertEquals(test.getNano(), 0);
}
示例10: factory_ofInstant_maxWithMinOffset
import java.time.OffsetDateTime; //导入方法依赖的package包/类
public void factory_ofInstant_maxWithMinOffset() {
long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
int year = Year.MAX_VALUE;
long days = (year * 365L + (year / 4 - year / 100 + year / 400)) + 365 - days_0000_to_1970;
Instant instant = Instant.ofEpochSecond((days + 1) * 24L * 60L * 60L - 1 - OFFSET_MIN.getTotalSeconds());
OffsetDateTime test = OffsetDateTime.ofInstant(instant, OFFSET_MIN);
assertEquals(test.getYear(), Year.MAX_VALUE);
assertEquals(test.getMonth().getValue(), 12);
assertEquals(test.getDayOfMonth(), 31);
assertEquals(test.getOffset(), OFFSET_MIN);
assertEquals(test.getHour(), 23);
assertEquals(test.getMinute(), 59);
assertEquals(test.getSecond(), 59);
assertEquals(test.getNano(), 0);
}
示例11: factory_ofInstant_nullInstant
import java.time.OffsetDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void factory_ofInstant_nullInstant() {
OffsetDateTime.ofInstant((Instant) null, OFFSET_PONE);
}
示例12: toOffsetDateTime
import java.time.OffsetDateTime; //导入方法依赖的package包/类
@Override
public OffsetDateTime toOffsetDateTime(Date date) {
Instant instant = date.toInstant();
return OffsetDateTime.ofInstant(instant, ZoneId.systemDefault());
}
示例13: factory_ofInstant_maxInstantWithMinOffset
import java.time.OffsetDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofInstant_maxInstantWithMinOffset() {
Instant instant = Instant.ofEpochSecond(Long.MAX_VALUE);
OffsetDateTime.ofInstant(instant, OFFSET_MIN);
}
示例14: factory_ofInstant_maxInstantWithMaxOffset
import java.time.OffsetDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofInstant_maxInstantWithMaxOffset() {
Instant instant = Instant.ofEpochSecond(Long.MAX_VALUE);
OffsetDateTime.ofInstant(instant, OFFSET_MAX);
}
示例15: factory_ofInstant_nullOffset
import java.time.OffsetDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void factory_ofInstant_nullOffset() {
Instant instant = Instant.ofEpochSecond(0L);
OffsetDateTime.ofInstant(instant, (ZoneOffset) null);
}