本文整理了Java中java.time.LocalDateTime.ofInstant()
方法的一些代码示例,展示了LocalDateTime.ofInstant()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.ofInstant()
方法的具体详情如下:
包路径:java.time.LocalDateTime
类名称:LocalDateTime
方法名:ofInstant
[英]Obtains an instance of LocalDateTime from an Instant and zone ID.
This creates a local date-time based on the specified instant. First, the offset from UTC/Greenwich is obtained using the zone ID and instant, which is simple as there is only one valid offset for each instant. Then, the instant and offset are used to calculate the local date-time.
[中]从即时和区域ID获取LocalDateTime的实例。
这将基于指定的瞬间创建本地日期时间。首先,使用区域ID和瞬间获得UTC/格林威治的偏移量,这很简单,因为每个瞬间只有一个有效偏移量。然后,使用即时和偏移量计算本地日期时间。
代码示例来源:origin: neo4j/neo4j
private static ZonedDateTime newZonedDateTime( long epochSecondLocal, long nano, ZoneId zoneId )
{
Instant instant = Instant.ofEpochSecond( epochSecondLocal, nano );
LocalDateTime localDateTime = LocalDateTime.ofInstant( instant, UTC );
return ZonedDateTime.of( localDateTime, zoneId );
}
}
代码示例来源:origin: lets-blade/blade
/**
* format date to string
*
* @param date date instance
* @param pattern date format pattern
* @return return string date
*/
public static String toString(Date date, String pattern) {
Instant instant = new java.util.Date((date.getTime())).toInstant();
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern(pattern));
}
代码示例来源:origin: oblac/jodd
public static LocalDateTime fromDate(final Date date) {
return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
}
代码示例来源:origin: lets-blade/blade
/**
* format date to string
*
* @param date date instance
* @param pattern date format pattern
* @return return string date
*/
public static String toString(Date date, String pattern) {
Instant instant = new java.util.Date((date.getTime())).toInstant();
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern(pattern));
}
代码示例来源:origin: lets-blade/blade
public static String gmtDate(Date date) {
return GMT_FMT.format(LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()).atZone(GMT_ZONE_ID));
}
代码示例来源:origin: lets-blade/blade
public static String gmtDate(Date date) {
return GMT_FMT.format(LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()).atZone(GMT_ZONE_ID));
}
代码示例来源:origin: yu199195/hmily
private Object convertDataTypeToDB(final Object params) {
//https://jdbc.postgresql.org/documentation/head/8-date-time.html
if (CommonConstant.DB_POSTGRESQL.equals(currentDBType) && params instanceof java.util.Date) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(((Date) params).getTime()), ZoneId.systemDefault());
}
return params;
}
代码示例来源:origin: neo4j/neo4j
public static LocalDateTime localDateTimeRaw( long epochSecond, long nano )
{
return assertValidArgument( () -> ofInstant( ofEpochSecond( epochSecond, nano ), UTC ) );
}
代码示例来源:origin: neo4j/neo4j
private LocalDateTime nextLocalDateTimeRaw()
{
return LocalDateTime.ofInstant( nextInstantRaw(), UTC );
}
代码示例来源:origin: apache/hive
public static String getTimestampString(Timestamp ts) {
return
LocalDateTime.ofInstant(Instant.ofEpochMilli(ts.getTime()), ZoneOffset.UTC)
.withNano(ts.getNanos())
.format(PRINT_FORMATTER);
}
}
代码示例来源:origin: apache/hive
public void setTimeInMillis(long epochMilli, int nanos) {
localDateTime = LocalDateTime
.ofInstant(Instant.ofEpochMilli(epochMilli), ZoneOffset.UTC)
.withNano(nanos);
}
代码示例来源:origin: nutzam/nutz
@Override
public TemporalAccessor cast(Number src, Class<?> toType, String... args) {
Date date = new Date(src.longValue());
LocalDateTime dt = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
if (toType == LocalDateTime.class)
return dt;
if (toType == LocalDate.class)
return dt.toLocalDate();
return dt.toLocalTime();
}
代码示例来源:origin: yu199195/hmily
/**
* Parse date string.
*
* @param date the date
* @return the string
*/
public static String parseDate(Date date) {
Instant instant = date.toInstant();
ZoneId zone = ZoneId.systemDefault();
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
return formatLocalDateTime(localDateTime);
}
代码示例来源:origin: apache/hive
public static Timestamp ofEpochMilli(long epochMilli) {
return new Timestamp(LocalDateTime
.ofInstant(Instant.ofEpochMilli(epochMilli), ZoneOffset.UTC));
}
代码示例来源:origin: apache/ignite
/** */
public String getFormattedStartTime() {
return dateTimeFormatter.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(startTime), TimeZone.getDefault().toZoneId()));
}
代码示例来源:origin: oblac/jodd
public static LocalDateTime fromCalendar(final Calendar calendar) {
TimeZone tz = calendar.getTimeZone();
ZoneId zid = tz == null ? ZoneId.systemDefault() : tz.toZoneId();
return LocalDateTime.ofInstant(calendar.toInstant(), zid);
}
代码示例来源:origin: apache/hive
@Override
protected void func(BytesColumnVector outV, TimestampColumnVector inV, int i) {
byte[] temp = LocalDateTime.ofInstant(Instant.ofEpochMilli(inV.time[i]), ZoneOffset.UTC)
.withNano(inV.nanos[i])
.format(PRINT_FORMATTER).getBytes();
assign(outV, i, temp, temp.length);
}
代码示例来源:origin: nutzam/nutz
@Override
public LocalDateTime cast(String src, Class<?> toType, String... args) {
// 处理空白
if (Strings.isBlank(src))
return null;
return LocalDateTime.ofInstant(toDate(src).toInstant(), ZoneId.systemDefault());
}
}
代码示例来源:origin: apache/hive
public static Timestamp ofEpochMilli(long epochMilli, int nanos) {
return new Timestamp(LocalDateTime
.ofInstant(Instant.ofEpochMilli(epochMilli), ZoneOffset.UTC)
.withNano(nanos));
}
代码示例来源:origin: hibernate/hibernate-orm
/**
* Set the transient property at load time based on a calculation.
* Note that a native Hibernate formula mapping is better for this purpose.
*/
@PostLoad
public void calculateAge() {
age = ChronoUnit.YEARS.between( LocalDateTime.ofInstant(
Instant.ofEpochMilli( dateOfBirth.getTime()), ZoneOffset.UTC),
LocalDateTime.now()
);
}
}
内容来源于网络,如有侵权,请联系作者删除!