gpt4 book ai didi

java.time.ZoneOffset.of()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 14:46:40 25 4
gpt4 key购买 nike

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

ZoneOffset.of介绍

[英]Obtains an instance of ZoneOffset using the ID.

This method parses the string ID of a ZoneOffset to return an instance. The parsing accepts all the formats generated by #getId(), plus some additional formats:

  • Z - for UTC
  • +h
  • +hh
  • +hh:mm
  • -hh:mm
  • +hhmm
  • -hhmm
  • +hh:mm:ss
  • -hh:mm:ss
  • +hhmmss
  • -hhmmss

Note that ± means either the plus or minus symbol.

The ID of the returned offset will be normalized to one of the formats described by #getId().

The maximum supported range is from +18:00 to -18:00 inclusive.
[中]使用ID获取ZoneOffset的实例。
此方法解析ZoneOffset的字符串ID以返回实例。解析接受#getId()生成的所有格式,以及一些其他格式:
*Z-代表UTC
*+h
*+hh
*+hh:mm
*-hh:mm
*+hhmm
*-hhmm
*+hh:mm:ss
*-hh:mm:ss
*+hhmms
*-hhmms
请注意,±表示加号或减号。
返回的偏移量的ID将标准化为#getId()描述的格式之一。
支持的最大范围为+18:00到-18:00(含18:00)。

代码示例

代码示例来源:origin: oracle/helidon

/**
 * Maps {@code stringValue} to {@code ZoneOffset}.
 *
 * @param stringValue source value as a {@code String}
 * @return mapped {@code stringValue} to {@code ZoneOffset}
 * @see ZoneOffset#of(String)
 */
public static ZoneOffset toZoneOffset(String stringValue) {
  return ZoneOffset.of(stringValue);
}

代码示例来源:origin: prestodb/presto

@Override
  protected ZoneOffset deserialize(String key, DeserializationContext ctxt) throws IOException {
    try {
      return ZoneOffset.of(key);
    } catch (DateTimeException e) {
      return _handleDateTimeException(ctxt, ZoneOffset.class, e, key);
    }
  }
}

代码示例来源:origin: prestodb/presto

private static ZoneOffset toZoneOffset(TimeZoneKey timeZoneKey)
{
  requireNonNull(timeZoneKey, "timeZoneKey is null");
  if (Objects.equals("UTC", timeZoneKey.getId())) {
    return ZoneOffset.UTC;
  }
  checkArgument(timeZoneKey.getId().matches("[+-]\\d\\d:\\d\\d"), "Not a zone-offset timezone: %s", timeZoneKey);
  return ZoneOffset.of(timeZoneKey.getId());
}

代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-jsr310

@Override
  protected ZoneOffset deserialize(String key, DeserializationContext ctxt) throws IOException {
    try {
      return ZoneOffset.of(key);
    } catch (DateTimeException e) {
      return _handleDateTimeException(ctxt, ZoneOffset.class, e, key);
    }
  }
}

代码示例来源:origin: embulk/embulk

/**
 * Parses a time zone ID to java.time.ZoneOffset basically in the same rule with Ruby v2.3.1's Time.strptime.
 *
 * The only difference from Ruby v2.3.1's Time.strptime is that it does not consider local time zone.
 * If the given zone is neither numerical nor predefined textual time zones, it returns defaultZoneOffset then.
 *
 * The method is reimplemented based on zone_offset from Ruby v2.3.1's lib/time.rb.
 *
 * @see <a href="https://svn.ruby-lang.org/cgi-bin/viewvc.cgi/tags/v2_3_1/lib/time.rb?view=markup#l134">zone_offset</a>
 */
public static ZoneOffset parseRubyTimeZoneOffset(final String zoneId, final ZoneOffset defaultZoneOffset) {
  if (zoneId == null) {
    return defaultZoneOffset;
  }
  if (zoneId.charAt(0) == '+' || zoneId.charAt(0) == '-') {
    if (RUBY_TIME_ZONE_OFFSET_PATTERN_HH_MM.matcher(zoneId).matches()
        || RUBY_TIME_ZONE_OFFSET_PATTERN_HH.matcher(zoneId).matches()) {
      return ZoneOffset.of(zoneId);
    }
    return defaultZoneOffset;
  }
  final ZoneOffset zoneOffset = RUBY_TIME_ZONE_OFFSET_IDS.get(zoneId.toUpperCase(Locale.ENGLISH));
  if (zoneOffset != null) {
    return zoneOffset;
  }
  return defaultZoneOffset;
}

代码示例来源:origin: debezium/debezium

public static int isZoneOffset(Configuration config, Field field, ValidationOutput problems) {
    String value = config.getString(field);
    if (value == null) return 0;
    try {
      ZoneOffset.of(value);
    } catch (DateTimeException e) {
      problems.accept(field, value, "A zone offset string representation is expected");
      return 1;
    }
    return 0;
  }
}

代码示例来源:origin: neo4j/neo4j

static OffsetTime defaultTime( ZoneId zoneId )
{
  return OffsetTime.of( TemporalFields.hour.defaultValue, TemporalFields.minute.defaultValue,
      TemporalFields.second.defaultValue, TemporalFields.nanosecond.defaultValue,
      assertValidZone( () -> ZoneOffset.of( zoneId.toString() ) ) );
}

代码示例来源:origin: embulk/embulk

public static TimestampFormatter of(final String pattern, final String zoneIdString) {
  if (pattern.startsWith("java:")) {
    final ZoneOffset zoneOffset;
    if (zoneIdString.equals("UTC")) {
      zoneOffset = ZoneOffset.UTC;
    } else {
      zoneOffset = ZoneOffset.of(zoneIdString);
    }
    return TimestampFormatterJava.of(pattern.substring(5), zoneOffset);
  } else if (pattern.startsWith("ruby:")) {
    final ZoneOffset zoneOffset;
    if (zoneIdString.equals("UTC")) {
      zoneOffset = ZoneOffset.UTC;
    } else {
      zoneOffset = ZoneOffset.of(zoneIdString);
    }
    return TimestampFormatterRuby.of(pattern.substring(5), zoneOffset);
  } else {
    return TimestampFormatterRuby.ofLegacy(pattern, TimeZoneIds.parseJodaDateTimeZone(zoneIdString));
  }
}

代码示例来源:origin: NLPchina/elasticsearch-sql

continue;
} else if ("time_zone".equals(kv.key)) {
  dateRange.timeZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone(ZoneOffset.of(value))));
  continue;
} else if ("from".equals(kv.key)) {

代码示例来源:origin: embulk/embulk

public static TimestampParser of(final String pattern,
                 final String defaultZoneIdString) {
  if (pattern.startsWith("java:")) {
    final ZoneOffset zoneOffset;
    if (defaultZoneIdString.equals("UTC")) {
      zoneOffset = ZoneOffset.UTC;
    } else {
      zoneOffset = ZoneOffset.of(defaultZoneIdString);
    }
    return TimestampParserJava.of(pattern.substring(5),
                   zoneOffset);
  } else if (pattern.startsWith("ruby:")) {
    final ZoneOffset zoneOffset;
    if (defaultZoneIdString.equals("UTC")) {
      zoneOffset = ZoneOffset.UTC;
    } else {
      zoneOffset = ZoneOffset.of(defaultZoneIdString);
    }
    return TimestampParserRuby.of(pattern.substring(5),
                   zoneOffset);
  } else {
    return TimestampParserLegacy.of(pattern,
                    TimeZoneIds.parseZoneIdWithJodaAndRubyZoneTab(defaultZoneIdString),
                    TimeZoneIds.parseJodaDateTimeZone(defaultZoneIdString),
                    1970,
                    1,
                    1);
  }
}

代码示例来源:origin: neo4j/neo4j

@Test
public void testIndexRangeSeekByTimeWithZonesAndDuplicates() throws Exception
{
  testIndexRangeSeekWithDuplicates( time( 20, 31, 53, 4, ZoneOffset.of("+17:02") ),
                   time( 20, 31, 54, 3, ZoneOffset.of("+17:02") ),
                   time( 19, 31, 54, 2, UTC ),
                   time( 18, 23, 27, 1, ZoneOffset.of("-18:00") ) );
}

代码示例来源:origin: prestodb/presto

return ZoneId.of(string);
case TYPE_ZONE_OFFSET:
  return ZoneOffset.of(string);

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldSendTime() throws Exception
{
  testSendingOfBoltV2Value( time( 424242, ZoneOffset.of( "+08:30" ) ) );
}

代码示例来源:origin: neo4j/neo4j

@Test
  public void compareToSameAsValue()
  {
    Value[] values = {TimeValue.time( 9999, ZoneOffset.of( "+18:00" ) ),
             TimeValue.time( 10000, ZoneOffset.of( "-18:00" ) ),
             TimeValue.time( 10000, ZoneOffset.of( "-00:00" ) ),
             TimeValue.time( 10000, ZoneOffset.of( "+01:00" ) ),
             TimeValue.time( 10000, ZoneOffset.of( "+03:00" ) ),
             TimeValue.time( 10000, ZoneOffset.of( "-18:00" ) )};

    ZonedTimeIndexKey keyI = new ZonedTimeIndexKey();
    ZonedTimeIndexKey keyJ = new ZonedTimeIndexKey();

    for ( Value vi : values )
    {
      for ( Value vj : values )
      {
        vi.writeTo( keyI );
        vj.writeTo( keyJ );

        int expected = Values.COMPARATOR.compare( vi, vj );
        assertEquals( format( "comparing %s and %s", vi, vj ), expected, keyI.compareValueTo( keyJ ) );
      }
    }
  }
}

代码示例来源:origin: neo4j/neo4j

@Test
void shouldNotEqualSameInstantButDifferentTimezone()
{
  assertNotEqual( time( 10000, UTC ), time( 10000, ZoneOffset.of( "+01:00" ) ) );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldNotEqualSameInstantButDifferentTimezone()
{
  assertNotEqual( datetime( 10000, 100, UTC ), datetime( 10000, 100, ZoneOffset.of( "+01:00" ) ) );
}

代码示例来源:origin: neo4j/neo4j

DateTimeValue.datetime( 10000, 100, ZoneOffset.of( "-17:59:59" ) ),
DateTimeValue.datetime( 10000, 100, ZoneId.of( "UTC" ) ),
DateTimeValue.datetime( 10000, 100, ZoneId.of( "+01:00" ) ),

代码示例来源:origin: neo4j/neo4j

@Test
void shouldCompareDerivedValue()
{
  TimeValue value1 = time( 4242, ZoneOffset.of( "-12:00" ) );
  TimeValue value2 = time( value1.temporal() );
  assertEquals( 0, value1.unsafeCompareTo( value2 ) );
}

代码示例来源:origin: neo4j/neo4j

@Test
void shouldWriteDerivedValueThatIsEqual()
{
  TimeValue value1 = time( 42, ZoneOffset.of( "-18:00" ) );
  TimeValue value2 = time( value1.temporal() );
  OffsetTime offsetTime1 = write( value1 );
  OffsetTime offsetTime2 = write( value2 );
  assertEquals( offsetTime1, offsetTime2 );
}

代码示例来源:origin: neo4j/neo4j

DateTimeValue.datetime( 9999, 100,  ZoneId.of( "+18:00" ) ),
DateTimeValue.datetime( 10000, 100, ZoneId.of( "-18:00" ) ),
DateTimeValue.datetime( 10000, 100, ZoneOffset.of( "-17:59:59" ) ),
DateTimeValue.datetime( 10000, 100, ZoneId.of( "UTC" ) ),
DateTimeValue.datetime( 10000, 100, ZoneId.of( "+01:00" ) ),

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com