java.time.OffsetDateTime.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.3k)|赞(0)|评价(0)|浏览(130)

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

OffsetDateTime.<init>介绍

[英]Constructor.
[中]建造师。

代码示例

代码示例来源:origin: com.github.seratch/java-time-backport

  1. /**
  2. * Obtains an instance of {@code OffsetDateTime} from a date-time and offset.
  3. * <p>
  4. * This creates an offset date-time with the specified local date-time and offset.
  5. *
  6. * @param dateTime the local date-time, not null
  7. * @param offset the zone offset, not null
  8. * @return the offset date-time, not null
  9. */
  10. public static OffsetDateTime of(LocalDateTime dateTime, ZoneOffset offset) {
  11. return new OffsetDateTime(dateTime, offset);
  12. }

代码示例来源:origin: com.github.seratch/java-time-backport

  1. /**
  2. * Obtains an instance of {@code OffsetDateTime} from a date, time and offset.
  3. * <p>
  4. * This creates an offset date-time with the specified local date, time and offset.
  5. *
  6. * @param date the local date, not null
  7. * @param time the local time, not null
  8. * @param offset the zone offset, not null
  9. * @return the offset date-time, not null
  10. */
  11. public static OffsetDateTime of(LocalDate date, LocalTime time, ZoneOffset offset) {
  12. LocalDateTime dt = LocalDateTime.of(date, time);
  13. return new OffsetDateTime(dt, offset);
  14. }

代码示例来源:origin: com.github.seratch/java-time-backport

  1. /**
  2. * Obtains an instance of {@code OffsetDateTime} from a year, month, day,
  3. * hour, minute, second, nanosecond and offset.
  4. * <p>
  5. * This creates an offset date-time with the seven specified fields.
  6. * <p>
  7. * This method exists primarily for writing test cases.
  8. * Non test-code will typically use other methods to create an offset time.
  9. * {@code LocalDateTime} has five additional convenience variants of the
  10. * equivalent factory method taking fewer arguments.
  11. * They are not provided here to reduce the footprint of the API.
  12. *
  13. * @param year the year to represent, from MIN_YEAR to MAX_YEAR
  14. * @param month the month-of-year to represent, from 1 (January) to 12 (December)
  15. * @param dayOfMonth the day-of-month to represent, from 1 to 31
  16. * @param hour the hour-of-day to represent, from 0 to 23
  17. * @param minute the minute-of-hour to represent, from 0 to 59
  18. * @param second the second-of-minute to represent, from 0 to 59
  19. * @param nanoOfSecond the nano-of-second to represent, from 0 to 999,999,999
  20. * @param offset the zone offset, not null
  21. * @return the offset date-time, not null
  22. * @throws DateTimeException if the value of any field is out of range, or
  23. * if the day-of-month is invalid for the month-year
  24. */
  25. public static OffsetDateTime of(
  26. int year, int month, int dayOfMonth,
  27. int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset) {
  28. LocalDateTime dt = LocalDateTime.of(year, month, dayOfMonth, hour, minute, second, nanoOfSecond);
  29. return new OffsetDateTime(dt, offset);
  30. }

代码示例来源:origin: com.jtransc/jtransc-rt

  1. public final class OffsetDateTime implements Temporal, TemporalAdjuster, Comparable<OffsetDateTime>, Serializable {
  2. public static final OffsetDateTime MIN = new OffsetDateTime(null, null);
  3. public static final OffsetDateTime MAX = new OffsetDateTime(null, null);

代码示例来源:origin: com.github.seratch/java-time-backport

  1. /**
  2. * Returns a new date-time based on this one, returning {@code this} where possible.
  3. *
  4. * @param dateTime the date-time to create with, not null
  5. * @param offset the zone offset to create with, not null
  6. */
  7. private OffsetDateTime with(LocalDateTime dateTime, ZoneOffset offset) {
  8. if (this.dateTime == dateTime && this.offset.equals(offset)) {
  9. return this;
  10. }
  11. return new OffsetDateTime(dateTime, offset);
  12. }

代码示例来源:origin: com.github.seratch/java-time-backport

  1. /**
  2. * Returns a copy of this {@code OffsetDateTime} with the specified offset ensuring
  3. * that the result is at the same instant.
  4. * <p>
  5. * This method returns an object with the specified {@code ZoneOffset} and a {@code LocalDateTime}
  6. * adjusted by the difference between the two offsets.
  7. * This will result in the old and new objects representing the same instant.
  8. * This is useful for finding the local time in a different offset.
  9. * For example, if this time represents {@code 2007-12-03T10:30+02:00} and the offset specified is
  10. * {@code +03:00}, then this method will return {@code 2007-12-03T11:30+03:00}.
  11. * <p>
  12. * To change the offset without adjusting the local time use {@link #withOffsetSameLocal}.
  13. * <p>
  14. * This instance is immutable and unaffected by this method call.
  15. *
  16. * @param offset the zone offset to change to, not null
  17. * @return an {@code OffsetDateTime} based on this date-time with the requested offset, not null
  18. * @throws DateTimeException if the result exceeds the supported date range
  19. */
  20. public OffsetDateTime withOffsetSameInstant(ZoneOffset offset) {
  21. if (offset.equals(this.offset)) {
  22. return this;
  23. }
  24. int difference = offset.getTotalSeconds() - this.offset.getTotalSeconds();
  25. LocalDateTime adjusted = dateTime.plusSeconds(difference);
  26. return new OffsetDateTime(adjusted, offset);
  27. }

代码示例来源:origin: com.github.seratch/java-time-backport

  1. /**
  2. * Obtains an instance of {@code OffsetDateTime} from an {@code Instant} and zone ID.
  3. * <p>
  4. * This creates an offset date-time with the same instant as that specified.
  5. * Finding the offset from UTC/Greenwich is simple as there is only one valid
  6. * offset for each instant.
  7. *
  8. * @param instant the instant to create the date-time from, not null
  9. * @param zone the time-zone, which may be an offset, not null
  10. * @return the offset date-time, not null
  11. * @throws DateTimeException if the result exceeds the supported range
  12. */
  13. public static OffsetDateTime ofInstant(Instant instant, ZoneId zone) {
  14. Jdk8Methods.requireNonNull(instant, "instant");
  15. Jdk8Methods.requireNonNull(zone, "zone");
  16. ZoneRules rules = zone.getRules();
  17. ZoneOffset offset = rules.getOffset(instant);
  18. LocalDateTime ldt = LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset);
  19. return new OffsetDateTime(ldt, offset);
  20. }

相关文章