gpt4 book ai didi

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

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

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

ZoneOffset.ofHoursMinutes介绍

[英]Obtains an instance of ZoneOffset using an offset in hours and minutes.

The sign of the hours and minutes components must match. Thus, if the hours is negative, the minutes must be negative or zero. If the hours is zero, the minutes may be positive, negative or zero.
[中]使用小时和分钟的偏移量获取ZoneOffset的实例。
小时和分钟组件的符号必须匹配。因此,如果小时数为负,分钟数必须为负或零。如果小时数为零,则分钟数可能为正、负或零。

代码示例

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

static ZoneOffset parseOffset( Matcher matcher )
{
  String zone = matcher.group( "zone" );
  if ( null == zone )
  {
    return null;
  }
  if ( "Z".equalsIgnoreCase( zone ) )
  {
    return UTC;
  }
  int factor = zone.charAt( 0 ) == '+' ? 1 : -1;
  int hours = parseInt( matcher.group( "zoneHour" ) );
  int minutes = optInt( matcher.group( "zoneMinute" ) );
  return assertValidZone( () -> ZoneOffset.ofHoursMinutes( factor * hours, factor * minutes ) );
}

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

@Test
void shouldTruncateOffsetSeconds()
{
  OffsetTime time = OffsetTime.of( 14, 55, 50, 0, ZoneOffset.ofHoursMinutesSeconds( 2, 15, 45 ) );
  OffsetTime truncatedTime = TemporalUtil.truncateOffsetToMinutes( time );
  assertEquals( OffsetTime.of( 14, 55, 5, 0, ZoneOffset.ofHoursMinutes( 2, 15 ) ), truncatedTime );
}

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

@Test
public void shouldSendDateTimeWithTimeZoneOffset() throws Exception
{
  testSendingOfBoltV2Value( datetime( 424242, 0, ZoneOffset.ofHoursMinutes( -7, -15 ) ) );
}

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

@Test
public void shouldSendAndReceiveDateTimeWithTimeZoneOffset() throws Exception
{
  testSendingAndReceivingOfBoltV2Value( datetime( 1899, 1, 1, 12, 12, 32, 0, ZoneOffset.ofHoursMinutes( -4, -15 ) ) );
}

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

@Test
public void shouldReceiveDateTimeWithTimeZoneOffset() throws Exception
{
  testReceivingOfBoltV2Value( "RETURN datetime({year:2022, month:3, day:2, hour:19, minute:10, timezone:'+02:30'})",
      datetime( 2022, 3, 2, 19, 10, 0, 0, ZoneOffset.ofHoursMinutes( 2, 30 ) ) );
}

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

@Test
public void shouldPackLocalDateTimeWithTimeZoneOffset()
{
  LocalDateTime localDateTime = LocalDateTime.of( 2015, 3, 23, 19, 15, 59, 10 );
  ZoneOffset offset = ZoneOffset.ofHoursMinutes( -5, -15 );
  ZonedDateTime zonedDateTime = ZonedDateTime.of( localDateTime, offset );
  PackedOutputArray packedOutput = pack( datetime( zonedDateTime ) );
  ByteBuffer buffer = ByteBuffer.wrap( packedOutput.bytes() );
  buffer.getShort(); // skip struct header
  assertEquals( INT_32, buffer.get() );
  assertEquals( localDateTime.toEpochSecond( UTC ), buffer.getInt() );
  assertEquals( localDateTime.getNano(), buffer.get() );
  assertEquals( INT_16, buffer.get() );
  assertEquals( offset.getTotalSeconds(), buffer.getShort() );
}

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

@Test
void shouldDoNothingForOffsetWithoutSeconds()
{
  OffsetTime time = OffsetTime.of( 23, 30, 10, 0, ZoneOffset.ofHoursMinutes( -5, -30 ) );
  OffsetTime truncatedTime = TemporalUtil.truncateOffsetToMinutes( time );
  assertEquals( time, truncatedTime );
}

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

@Test
void shouldHandleDateTimeWithTimeZoneOffset()
{
  DateTimeValue datetime = datetime( 1988, 4, 19, 10, 12, 59, 112233445, ZoneOffset.ofHoursMinutes( 3, 15 ) );
  PrettyPrinter printer = new PrettyPrinter();
  datetime.writeTo( printer );
  assertEquals( "{datetime: \"1988-04-19T10:12:59.112233445+03:15\"}", printer.value() );
}

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

@Test
void shouldHandleTime()
{
  TimeValue time = time( 11, 19, 11, 123456789, ZoneOffset.ofHoursMinutes( -9, -30 ) );
  PrettyPrinter printer = new PrettyPrinter();
  time.writeTo( printer );
  assertEquals( "{time: \"11:19:11.123456789-09:30\"}", printer.value() );
}

代码示例来源:origin: com.github.marschall/threeten-jpa-oracle-impl

private static ZoneOffset extractOffset(byte[] bytes) {
 int hours = bytes[11] - 20;
 int minutes = bytes[12] - 60;
 if (hours == 0 && minutes == 0) {
  return ZoneOffset.UTC;
 }
 return ZoneOffset.ofHoursMinutes(hours, minutes);
}

代码示例来源:origin: marschall/threeten-jpa

private static ZoneOffset extractOffset(byte[] bytes) {
 int hours = bytes[11] - 20;
 int minutes = bytes[12] - 60;
 if (hours == 0 && minutes == 0) {
  return ZoneOffset.UTC;
 }
 return ZoneOffset.ofHoursMinutes(hours, minutes);
}

代码示例来源:origin: kousen/java_8_recipes

public static List<String> getRegionNamesForOffset(int hours, int minutes) {
    ZoneOffset offset = ZoneOffset.ofHoursMinutes(hours, minutes);
    return getRegionNamesForOffset(offset);
  }
}

代码示例来源:origin: apache/james-project

@Test
void offsetShouldBeParsed() {
  ZonedDateTime dateTime = ZonedDateTime.parse("3 Jun 2017 04:35:11 -0712", ImapDateTimeFormatter.rfc5322());
  assertThat(dateTime.getOffset()).isEqualTo(ZoneOffset.ofHoursMinutes(-7, -12));
}

代码示例来源:origin: org.apache.james/james-server-util-java8

@Test
public void offsetShouldBeParsed() {
  ZonedDateTime dateTime = ZonedDateTime.parse("3 Jun 2017 04:35:11 -0712", ImapDateTimeFormatter.rfc5322());
  assertThat(dateTime.getOffset()).isEqualTo(ZoneOffset.ofHoursMinutes(-7, -12));
}

代码示例来源:origin: com.hubspot.jinjava/jinjava

@Test
public void itConvertsStringToTime() {
 String datetime = "2018-07-14T14:31:30+0530";
 String format = "yyyy-MM-dd'T'HH:mm:ssZ";
 PyishDate expected = new PyishDate(ZonedDateTime.of(2018, 7, 14, 14, 31, 30, 0, ZoneOffset.ofHoursMinutes(5, 30)));
 assertThat(Functions.stringToTime(datetime, format)).isEqualTo(expected);
}

代码示例来源:origin: HubSpot/jinjava

@Test
public void itConvertsStringToTime() {
 String datetime = "2018-07-14T14:31:30+0530";
 String format = "yyyy-MM-dd'T'HH:mm:ssZ";
 PyishDate expected = new PyishDate(ZonedDateTime.of(2018, 7, 14, 14, 31, 30, 0, ZoneOffset.ofHoursMinutes(5, 30)));
 assertThat(Functions.stringToTime(datetime, format)).isEqualTo(expected);
}

代码示例来源:origin: com.hubspot.jinjava/jinjava

@Test(expected = InterpretException.class)
public void itFailsOnInvalidFormat() {
 String datetime = "2018-07-14T14:31:30+0530";
 String format = "not a time format";
 PyishDate expected = new PyishDate(ZonedDateTime.of(2018, 7, 14, 14, 31, 30, 0, ZoneOffset.ofHoursMinutes(5, 30)));
 assertThat(Functions.stringToTime(datetime, format)).isEqualTo(expected);
}

代码示例来源:origin: HubSpot/jinjava

@Test(expected = InterpretException.class)
public void itFailsOnInvalidFormat() {
 String datetime = "2018-07-14T14:31:30+0530";
 String format = "not a time format";
 PyishDate expected = new PyishDate(ZonedDateTime.of(2018, 7, 14, 14, 31, 30, 0, ZoneOffset.ofHoursMinutes(5, 30)));
 assertThat(Functions.stringToTime(datetime, format)).isEqualTo(expected);
}

代码示例来源:origin: HubSpot/jinjava

@Test(expected = InterpretException.class)
public void itFailsOnTimeFormatMismatch() {
 String datetime = "Saturday, Jul 14, 2018 14:31:06 PM";
 String format = "yyyy-MM-dd'T'HH:mm:ssZ";
 PyishDate expected = new PyishDate(ZonedDateTime.of(2018, 7, 14, 14, 31, 30, 0, ZoneOffset.ofHoursMinutes(5, 30)));
 assertThat(Functions.stringToTime(datetime, format)).isEqualTo(expected);
}

代码示例来源:origin: com.hubspot.jinjava/jinjava

@Test(expected = InterpretException.class)
public void itFailsOnTimeFormatMismatch() {
 String datetime = "Saturday, Jul 14, 2018 14:31:06 PM";
 String format = "yyyy-MM-dd'T'HH:mm:ssZ";
 PyishDate expected = new PyishDate(ZonedDateTime.of(2018, 7, 14, 14, 31, 30, 0, ZoneOffset.ofHoursMinutes(5, 30)));
 assertThat(Functions.stringToTime(datetime, format)).isEqualTo(expected);
}

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