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

x33g5p2x  于2022-01-26 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(281)

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

OffsetDateTime.of介绍

[英]Obtains an instance of OffsetDateTime from a year, month, day, hour, minute, second, nanosecond and offset.

This creates an offset date-time with the seven specified fields.

This method exists primarily for writing test cases. Non test-code will typically use other methods to create an offset time. LocalDateTime has five additional convenience variants of the equivalent factory method taking fewer arguments. They are not provided here to reduce the footprint of the API.
[中]从年、月、日、小时、分钟、秒、纳秒和偏移量中获取OffsetDateTime的实例。
这将创建带有七个指定字段的偏移日期时间。
这种方法主要用于编写测试用例。非测试代码通常会使用其他方法来创建偏移时间。LocalDateTime有五个附加的方便变量,它们是等效工厂方法的变体,使用的参数更少。这里不提供它们是为了减少API的占用空间。

代码示例

代码示例来源:origin: org.threeten/threetenbp

/**
 * Converts this date-time to an {@code OffsetDateTime}.
 * <p>
 * This creates an offset date-time using the local date-time and offset.
 * The zone ID is ignored.
 *
 * @return an offset date-time representing the same local date-time and offset, not null
 */
public OffsetDateTime toOffsetDateTime() {
  return OffsetDateTime.of(dateTime, offset);
}

代码示例来源:origin: ThreeTen/threetenbp

try {
  LocalDateTime ldt = LocalDateTime.from(temporal);
  return OffsetDateTime.of(ldt, offset);
} catch (DateTimeException ignore) {
  Instant instant = Instant.from(temporal);

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Combines this time with a date to create an {@code OffsetDateTime}.
 * <p>
 * This returns an {@code OffsetDateTime} formed from this time and the specified date.
 * All possible combinations of date and time are valid.
 *
 * @param date  the date to combine with, not null
 * @return the offset date-time formed from this time and the specified date, not null
 */
public OffsetDateTime atDate(LocalDate date) {
  return OffsetDateTime.of(date, time, offset);
}

代码示例来源:origin: org.threeten/threetenbp

try {
  LocalDateTime ldt = LocalDateTime.from(temporal);
  return OffsetDateTime.of(ldt, offset);
} catch (DateTimeException ignore) {
  Instant instant = Instant.from(temporal);

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Combines this date-time with an offset to create an {@code OffsetDateTime}.
 * <p>
 * This returns an {@code OffsetDateTime} formed from this date-time at the specified offset.
 * All possible combinations of date-time and offset are valid.
 *
 * @param offset  the offset to combine with, not null
 * @return the offset date-time formed from this date-time and the specified offset, not null
 */
public OffsetDateTime atOffset(ZoneOffset offset) {
  return OffsetDateTime.of(this, offset);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Converts this date-time to an {@code OffsetDateTime}.
 * <p>
 * This creates an offset date-time using the local date-time and offset.
 * The zone ID is ignored.
 *
 * @return an offset date-time representing the same local date-time and offset, not null
 */
public OffsetDateTime toOffsetDateTime() {
  return OffsetDateTime.of(dateTime, offset);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Combines this date-time with an offset to create an {@code OffsetDateTime}.
 * <p>
 * This returns an {@code OffsetDateTime} formed from this date-time at the specified offset.
 * All possible combinations of date-time and offset are valid.
 *
 * @param offset  the offset to combine with, not null
 * @return the offset date-time formed from this date-time and the specified offset, not null
 */
public OffsetDateTime atOffset(ZoneOffset offset) {
  return OffsetDateTime.of(this, offset);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Combines this time with a date to create an {@code OffsetDateTime}.
 * <p>
 * This returns an {@code OffsetDateTime} formed from this time and the specified date.
 * All possible combinations of date and time are valid.
 *
 * @param date  the date to combine with, not null
 * @return the offset date-time formed from this time and the specified date, not null
 */
public OffsetDateTime atDate(LocalDate date) {
  return OffsetDateTime.of(date, time, offset);
}

代码示例来源:origin: guanpj/JReadHub

public static OffsetDateTime string2ODT(String timeStr) {
    if (!TextUtils.isEmpty(timeStr)) {
      DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
      LocalDateTime localDateTime = LocalDateTime.parse(timeStr, df);
      return OffsetDateTime.of(localDateTime, ZoneOffset.UTC);
    }
    return null;
  }
}

代码示例来源:origin: ThreeTen/threetenbp

static OffsetDateTime readExternal(DataInput in) throws IOException {
  LocalDateTime dateTime = LocalDateTime.readExternal(in);
  ZoneOffset offset = ZoneOffset.readExternal(in);
  return OffsetDateTime.of(dateTime, offset);
}

代码示例来源:origin: org.threeten/threetenbp

static OffsetDateTime readExternal(DataInput in) throws IOException {
  LocalDateTime dateTime = LocalDateTime.readExternal(in);
  ZoneOffset offset = ZoneOffset.readExternal(in);
  return OffsetDateTime.of(dateTime, offset);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Combines this date with an offset time to create an {@code OffsetDateTime}.
 * <p>
 * This returns an {@code OffsetDateTime} formed from this date at the specified time.
 * All possible combinations of date and time are valid.
 *
 * @param time  the time to combine with, not null
 * @return the offset date-time formed from this date and the specified time, not null
 */
public OffsetDateTime atTime(OffsetTime time) {
  return OffsetDateTime.of(LocalDateTime.of(this, time.toLocalTime()), time.getOffset());
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Combines this date with an offset time to create an {@code OffsetDateTime}.
 * <p>
 * This returns an {@code OffsetDateTime} formed from this date at the specified time.
 * All possible combinations of date and time are valid.
 *
 * @param time  the time to combine with, not null
 * @return the offset date-time formed from this date and the specified time, not null
 */
public OffsetDateTime atTime(OffsetTime time) {
  return OffsetDateTime.of(LocalDateTime.of(this, time.toLocalTime()), time.getOffset());
}

代码示例来源:origin: alexvoronov/geonetworking

/** Returns TAI milliseconds mod 2^32 for the given date.
 *
 * Since java int is signed 32 bit integer, return long instead.
 * It is the same on byte level, but just to avoid confusing people with negative values here.
 *
 *
 * From http://stjarnhimlen.se/comp/time.html:
 *
 * TAI (Temps Atomique International or International Atomic Time) is
 * defined as the weighted average of the time kept by about 200
 * atomic clocks in over 50 national laboratories worldwide.
 * TAI-UT1 was approximately 0 on 1958 Jan 1.
 * (TAI is ahead of UTC by 35 seconds as of 2014.)
 *
 * GPS time = TAI - 19 seconds.  GPS time matched UTC from 1980-01-01
 * to 1981-07-01.  No leap seconds are inserted into GPS time, thus
 * GPS time is 13 seconds ahead of UTC on 2000-01-01.  The GPS epoch
 * is 00:00 (midnight) UTC on 1980-01-06.
 * The difference between GPS Time and UTC changes in increments of
 * seconds each time a leap second is added to UTC time scale.
 */
public static long instantToTaiMillisSince2004Mod32(Instant instantX) {
  OffsetDateTime gnEpochStart =
      OffsetDateTime.of(LocalDateTime.of(2004, Month.JANUARY, 1, 0, 0), ZoneOffset.UTC);
  long millis2004 = gnEpochStart.toInstant().toEpochMilli();
  long millisAtX = instantX.toEpochMilli();
  long taiMillis = (millisAtX + LEAP_SECONDS_SINCE_2004*1000) - millis2004;
  return taiMillis % (1L << 32);
}

代码示例来源:origin: ngs-doo/dsl-json

if (tmp[19] == '.') {
    final int nanos = readNanos(tmp, len - 1);
    return OffsetDateTime.of(year, month, day, hour, min, sec, nanos, ZoneOffset.UTC);
  return OffsetDateTime.of(year, month, day, hour, min, sec, 0, ZoneOffset.UTC);
} else if (len > 22 && len < 36 && tmp[len - 3] == ':'
    && (tmp[len - 6] == '+' || tmp[len - 6] == '-')
  if (tmp[19] == '.') {
    final int nanos = readNanos(tmp, len - 6);
    return OffsetDateTime.of(year, month, day, hour, min, sec, nanos, offset);
  return OffsetDateTime.of(year, month, day, hour, min, sec, 0, offset);
} else {
  return OffsetDateTime.parse(new String(tmp, 0, len));

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

OffsetDateTime invModified =  OffsetDateTime.of(LocalDateTime.of(2018, 12, 06, 15, 00), ZoneOffset.UTC);

相关文章