org.threeten.bp.Instant.atZone()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(2.3k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中org.threeten.bp.Instant.atZone()方法的一些代码示例,展示了Instant.atZone()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instant.atZone()方法的具体详情如下:
包路径:org.threeten.bp.Instant
类名称:Instant
方法名:atZone

Instant.atZone介绍

[英]Combines this instant with a time-zone to create a ZonedDateTime.

This returns an ZonedDateTime formed from this instant at the specified time-zone. An exception will be thrown if the instant is too large to fit into a zoned date-time.

This method is equivalent to ZonedDateTime#ofInstant(Instant,ZoneId).
[中]将此即时与时区组合以创建ZonedDateTime。
这将返回从此时刻在指定时区形成的ZonedDateTime。如果瞬间太大,无法放入分区日期时间,将引发异常。
此方法相当于ZoneDateTime#of Instant(Instant,ZoneId)。

代码示例

代码示例来源:origin: jeffdcamp/dbtools-android

@Nullable
public static LocalDateTime longToLocalDateTimeUtc(@Nullable Long l) {
  if (l == null) {
    return null;
  }
  return Instant.ofEpochMilli(l).atZone(ZoneOffset.UTC).toLocalDateTime();
}

代码示例来源:origin: XeroAPI/Xero-Java

public OffsetDateTime deserialize(JsonParser jsonparser, DeserializationContext context)
   throws IOException, JsonProcessingException {
    String date = jsonparser.getText();
    OffsetDateTime formattedDate;
    Pattern datePatt = Pattern.compile("^/Date\\((\\d+)([+-]\\d+)?\\)/$");
    Matcher m = datePatt.matcher(date);
    if (m.matches()) {
      Long l = Long.parseLong(m.group(1));
      formattedDate = Instant.ofEpochMilli(l).atZone(ZoneId.systemDefault()).toOffsetDateTime();
    } else {
      throw new IllegalArgumentException("Wrong date format");
    }
    return formattedDate;
  }
}

代码示例来源:origin: XeroAPI/Xero-Java

public LocalDate deserialize(JsonParser jsonparser, DeserializationContext context)
   throws IOException, JsonProcessingException {
    String date = jsonparser.getText();
    LocalDate formattedDate;
    Pattern datePatt = Pattern.compile("^/Date\\((\\d+)([+-]\\d+)?\\)/$");
    Matcher m = datePatt.matcher(date);
    if (m.matches()) {
      Long l = Long.parseLong(m.group(1));
      formattedDate = Instant.ofEpochMilli(l).atZone(ZoneId.systemDefault()).toLocalDate();
    } else {
      throw new IllegalArgumentException("Wrong date format");
    }
    return formattedDate;
  }
}

代码示例来源:origin: jeffdcamp/dbtools-android

@Nullable
public static LocalDateTime longToLocalDateTime(@Nullable Long l) {
  if (l == null) {
    return null;
  }
  return Instant.ofEpochMilli(l).atZone(ZoneId.systemDefault()).toLocalDateTime();
}

代码示例来源:origin: apache/servicemix-bundles

@Nonnull
  @Override
  public Date convert(Instant source) {
    return toDate(source.atZone(systemDefault()).toInstant());
  }
}

相关文章