gpt4 book ai didi

java.time.Year.now()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 22:58:40 27 4
gpt4 key购买 nike

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

Year.now介绍

[英]Obtains the current year from the system clock in the default time-zone.

This will query the Clock#systemDefaultZone() in the default time-zone to obtain the current year.

Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
[中]从默认时区的系统时钟获取当前年份。
这将查询默认时区中的时钟#systemDefaultZone(),以获取当前年份。
使用此方法将防止使用备用时钟进行测试,因为该时钟是硬编码的。

代码示例

代码示例来源:origin: kiegroup/optaplanner

private void writeTimeGrainDaysHeaders() {
  Day previousTimeGrainDay = null;
  int mergeStart = -1;
  for (TimeGrain timeGrain : solution.getTimeGrainList()) {
    Day timeGrainDay = timeGrain.getDay();
    if (timeGrainDay.equals(previousTimeGrainDay)) {
      nextHeaderCell("");
    } else {
      if (previousTimeGrainDay != null) {
        currentSheet.addMergedRegion(new CellRangeAddress(currentRowNumber, currentRowNumber, mergeStart, currentColumnNumber));
      }
      nextHeaderCell(DAY_FORMATTER.format(
          LocalDate.ofYearDay(Year.now().getValue(), timeGrainDay.getDayOfYear())));
      previousTimeGrainDay = timeGrainDay;
      mergeStart = currentColumnNumber;
    }
  }
  if (previousTimeGrainDay != null) {
    currentSheet.addMergedRegion(new CellRangeAddress(currentRowNumber, currentRowNumber, mergeStart, currentColumnNumber));
  }
}

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

assertTrue(immutability.test(ValueRange.of(0L, 10L)));
assertTrue(immutability.test(WeekFields.ISO));
assertTrue(immutability.test(Year.now()));
assertTrue(immutability.test(YearMonth.now()));
assertTrue(immutability.test(ZoneOffset.UTC));

代码示例来源:origin: kiegroup/optaplanner

private void writeDays() {
  nextSheet("Days", 1, 1, false);
  nextRow();
  nextHeaderCell("Day");
  nextHeaderCell("Start");
  nextHeaderCell("End");
  nextHeaderCell("Lunch hour start time");
  for (Day dayOfYear : solution.getDayList()) {
    nextRow();
    LocalDate date = LocalDate.ofYearDay(Year.now().getValue(), dayOfYear.getDayOfYear());
    int startMinuteOfDay = 24 * 60, endMinuteOfDay = 0;
    for (TimeGrain timeGrain : solution.getTimeGrainList()) {
      if (timeGrain.getDay().equals(dayOfYear)) {
        startMinuteOfDay = timeGrain.getStartingMinuteOfDay() < startMinuteOfDay ?
            timeGrain.getStartingMinuteOfDay() : startMinuteOfDay;
        endMinuteOfDay = timeGrain.getStartingMinuteOfDay() + TimeGrain.GRAIN_LENGTH_IN_MINUTES > endMinuteOfDay ?
            timeGrain.getStartingMinuteOfDay() + TimeGrain.GRAIN_LENGTH_IN_MINUTES : endMinuteOfDay;
      }
    }
    LocalTime startTime = LocalTime.ofSecondOfDay(startMinuteOfDay * 60);
    LocalTime endTime = LocalTime.ofSecondOfDay(endMinuteOfDay * 60);
    LocalTime lunchHourStartTime = LocalTime.ofSecondOfDay(12 * 60 * 60); // 12pm
    nextCell().setCellValue(DAY_FORMATTER.format(date));
    nextCell().setCellValue(TIME_FORMATTER.format(startTime));
    nextCell().setCellValue(TIME_FORMATTER.format(endTime));
    nextCell().setCellValue(TIME_FORMATTER.format(lunchHourStartTime));
  }
  autoSizeColumnsWithHeader();
}

代码示例来源:origin: apache/metron

@SuppressWarnings("rawtypes")
 @Test
 public void testTimestampParsing() throws ParseException {
  JSONObject parsed = parser.parse(fireeyeMessage.getBytes()).get(0);
  JSONParser parser = new JSONParser();
  Map json = (Map) parser.parse(parsed.toJSONString());
  long expectedTimestamp = ZonedDateTime.of(Year.now(ZoneOffset.UTC).getValue(), 3, 19, 5, 24, 39, 0, ZoneOffset.UTC).toInstant().toEpochMilli();
  Assert.assertEquals(expectedTimestamp, json.get("timestamp"));
 }
}

代码示例来源:origin: apache/metron

@Test
public void testParseRBMLine() throws Exception {
  
  //Set up parser, parse message
  GrokWebSphereParser parser = new GrokWebSphereParser();
  parser.configure(parserConfig);
  String testString = "<131>Apr 15 17:36:35 ROBXML3QRS [0x80800018][auth][error] rbm(RBM-Settings): "
      + "trans(3502888135)[request] gtid(3502888135): RBM: Resource access denied.";
  Optional<MessageParserResult<JSONObject>> resultOptional = parser.parseOptionalResult(testString.getBytes());
  Assert.assertNotNull(resultOptional);
  Assert.assertTrue(resultOptional.isPresent());
  List<JSONObject> result = resultOptional.get().getMessages();
  JSONObject parsedJSON = result.get(0);
  long expectedTimestamp = ZonedDateTime.of(Year.now(UTC).getValue(), 4, 15, 17, 36, 35, 0, UTC).toInstant().toEpochMilli();
  
  //Compare fields
  assertEquals(131, parsedJSON.get("priority"));
  assertEquals(expectedTimestamp, parsedJSON.get("timestamp"));
  assertEquals("ROBXML3QRS", parsedJSON.get("hostname"));
  assertEquals("0x80800018", parsedJSON.get("event_code"));
  assertEquals("auth", parsedJSON.get("event_type"));
  assertEquals("error", parsedJSON.get("severity"));
  assertEquals("rbm", parsedJSON.get("process"));
  assertEquals("trans(3502888135)[request] gtid(3502888135): RBM: Resource access denied.", parsedJSON.get("message"));
}

代码示例来源:origin: apache/metron

@Test
public void testParseOtherLine() throws Exception {
  
  //Set up parser, parse message
  GrokWebSphereParser parser = new GrokWebSphereParser();
  parser.configure(parserConfig);
  String testString = "<134>Apr 15 17:17:34 SAGPXMLQA333 [0x8240001c][audit][info] trans(191): (admin:default:system:*): "
      + "ntp-service 'NTP Service' - Operational state down";
  Optional<MessageParserResult<JSONObject>> resultOptional = parser.parseOptionalResult(testString.getBytes());
  Assert.assertNotNull(resultOptional);
  Assert.assertTrue(resultOptional.isPresent());
  List<JSONObject> result = resultOptional.get().getMessages();
  JSONObject parsedJSON = result.get(0);
  long expectedTimestamp = ZonedDateTime.of(Year.now(UTC).getValue(), 4, 15, 17, 17, 34, 0, UTC).toInstant().toEpochMilli();
  
  //Compare fields
  assertEquals(134, parsedJSON.get("priority"));
  assertEquals(expectedTimestamp, parsedJSON.get("timestamp"));
  assertEquals("SAGPXMLQA333", parsedJSON.get("hostname"));
  assertEquals("0x8240001c", parsedJSON.get("event_code"));
  assertEquals("audit", parsedJSON.get("event_type"));
  assertEquals("info", parsedJSON.get("severity"));
  assertEquals("trans", parsedJSON.get("process"));
  assertEquals("(admin:default:system:*): ntp-service 'NTP Service' - Operational state down", parsedJSON.get("message"));
}

代码示例来源:origin: apache/metron

@Test
public void testParseMalformedRBMLine() throws Exception {
  
  //Set up parser, parse message
  GrokWebSphereParser parser = new GrokWebSphereParser();
  parser.configure(parserConfig);
  String testString = "<131>Apr 15 17:36:35 ROBXML3QRS [0x80800018][auth][error] rbmRBM-Settings): "
      + "trans3502888135)[request] gtid3502888135) RBM: Resource access denied.";
  Optional<MessageParserResult<JSONObject>> resultOptional = parser.parseOptionalResult(testString.getBytes());
  Assert.assertNotNull(resultOptional);
  Assert.assertTrue(resultOptional.isPresent());
  List<JSONObject> result = resultOptional.get().getMessages();
  JSONObject parsedJSON = result.get(0);
  long expectedTimestamp = ZonedDateTime.of(Year.now(UTC).getValue(), 4, 15, 17, 36, 35, 0, UTC).toInstant().toEpochMilli();
  
  //Compare fields
  assertEquals(131, parsedJSON.get("priority"));
  assertEquals(expectedTimestamp, parsedJSON.get("timestamp"));
  assertEquals("ROBXML3QRS", parsedJSON.get("hostname"));
  assertEquals("0x80800018", parsedJSON.get("event_code"));
  assertEquals("auth", parsedJSON.get("event_type"));
  assertEquals("error", parsedJSON.get("severity"));
  assertEquals(null, parsedJSON.get("process"));
  assertEquals("rbmRBM-Settings): trans3502888135)[request] gtid3502888135) RBM: Resource access denied.", parsedJSON.get("message"));
}

代码示例来源:origin: apache/metron

@Test
public void testParseMalformedOtherLine() throws Exception {
  
  //Set up parser, parse message
  GrokWebSphereParser parser = new GrokWebSphereParser();
  parser.configure(parserConfig);
  String testString = "<134>Apr 15 17:17:34 SAGPXMLQA333 [0x8240001c][audit][info] trans 191)  admindefaultsystem*): "
      + "ntp-service 'NTP Service' - Operational state down:";
  Optional<MessageParserResult<JSONObject>> resultOptional = parser.parseOptionalResult(testString.getBytes());
  Assert.assertNotNull(resultOptional);
  Assert.assertTrue(resultOptional.isPresent());
  List<JSONObject> result = resultOptional.get().getMessages();
  JSONObject parsedJSON = result.get(0);
  long expectedTimestamp = ZonedDateTime.of(Year.now(UTC).getValue(), 4, 15, 17, 17, 34, 0, UTC).toInstant().toEpochMilli();
  
  //Compare fields
  assertEquals(134, parsedJSON.get("priority"));
  assertEquals(expectedTimestamp, parsedJSON.get("timestamp"));
  assertEquals("SAGPXMLQA333", parsedJSON.get("hostname"));
  assertEquals("0x8240001c", parsedJSON.get("event_code"));
  assertEquals("audit", parsedJSON.get("event_type"));
  assertEquals("info", parsedJSON.get("severity"));
  assertEquals(null, parsedJSON.get("process"));
  assertEquals("trans 191)  admindefaultsystem*): ntp-service 'NTP Service' - Operational state down:", parsedJSON.get("message"));
}

代码示例来源:origin: apache/metron

@Test
public void testParseLogoutLine() throws Exception {
  
  //Set up parser, parse message
  GrokWebSphereParser parser = new GrokWebSphereParser();
  parser.configure(parserConfig);
  String testString = "<134>Apr 15 18:02:27 PHIXML3RWD [0x81000019][auth][info] [14.122.2.201]: "
      + "User 'hjpotter' logged out from 'default'.";
  Optional<MessageParserResult<JSONObject>> resultOptional = parser.parseOptionalResult(testString.getBytes());
  Assert.assertNotNull(resultOptional);
  Assert.assertTrue(resultOptional.isPresent());
  List<JSONObject> result = resultOptional.get().getMessages();
  JSONObject parsedJSON = result.get(0);
  long expectedTimestamp = ZonedDateTime.of(Year.now(UTC).getValue(), 4, 15, 18, 2, 27, 0, UTC).toInstant().toEpochMilli();
  
  //Compare fields
  assertEquals(134, parsedJSON.get("priority"));
  assertEquals(expectedTimestamp, parsedJSON.get("timestamp"));
  assertEquals("PHIXML3RWD", parsedJSON.get("hostname"));
  assertEquals("0x81000019", parsedJSON.get("event_code"));
  assertEquals("auth", parsedJSON.get("event_type"));
  assertEquals("info", parsedJSON.get("severity"));
  assertEquals("14.122.2.201", parsedJSON.get("ip_src_addr"));
  assertEquals("hjpotter", parsedJSON.get("username"));
  assertEquals("default", parsedJSON.get("security_domain"));
}

代码示例来源:origin: apache/metron

@Test
public void testParseMalformedLogoutLine() throws Exception {
  
  //Set up parser, attempt to parse malformed message
  GrokWebSphereParser parser = new GrokWebSphereParser();
  parser.configure(parserConfig);
  String testString = "<134>Apr 15 18:02:27 PHIXML3RWD [0x81000019][auth][info] [14.122.2.201: "
      + "User 'hjpotter' logged out from 'default.";
  Optional<MessageParserResult<JSONObject>> resultOptional = parser.parseOptionalResult(testString.getBytes());
  Assert.assertNotNull(resultOptional);
  Assert.assertTrue(resultOptional.isPresent());
  List<JSONObject> result = resultOptional.get().getMessages();
  JSONObject parsedJSON = result.get(0);
  long expectedTimestamp = ZonedDateTime.of(Year.now(UTC).getValue(), 4, 15, 18, 2, 27, 0, UTC).toInstant().toEpochMilli();
  
  //Compare fields
  assertEquals(134, parsedJSON.get("priority"));
  assertEquals(expectedTimestamp, parsedJSON.get("timestamp"));
  assertEquals("PHIXML3RWD", parsedJSON.get("hostname"));
  assertEquals("0x81000019", parsedJSON.get("event_code"));
  assertEquals("auth", parsedJSON.get("event_type"));
  assertEquals("info", parsedJSON.get("severity"));
  assertEquals(null, parsedJSON.get("ip_src_addr"));
  assertEquals(null, parsedJSON.get("username"));
  assertEquals(null, parsedJSON.get("security_domain"));
}

代码示例来源:origin: org.hibernate.validator/hibernate-validator

@Override
protected Year getReferenceValue(Clock reference) {
  return Year.now( reference );
}

代码示例来源:origin: apache/metron

@Test
public void testParseMalformedLoginLine() throws Exception {
  
  //Set up parser, attempt to parse malformed message
  GrokWebSphereParser parser = new GrokWebSphereParser();
  parser.configure(parserConfig);
  String testString = "<133>Apr 15 17:47:28 ABCXML1413 [rojOut][0x81000033][auth][notice] rick007): "
      + "[120.43.200. User logged into 'cohlOut'.";
  Optional<MessageParserResult<JSONObject>> resultOptional = parser.parseOptionalResult(testString.getBytes());
  Assert.assertNotNull(resultOptional);
  Assert.assertTrue(resultOptional.isPresent());
  List<JSONObject> result = resultOptional.get().getMessages();
  JSONObject parsedJSON = result.get(0);
  long expectedTimestamp = ZonedDateTime.of(Year.now(UTC).getValue(), 4, 15, 17, 47, 28, 0, UTC).toInstant().toEpochMilli();
  //Compare fields
  assertEquals(133, parsedJSON.get("priority"));
  assertEquals(expectedTimestamp, parsedJSON.get("timestamp"));
  assertEquals("ABCXML1413", parsedJSON.get("hostname"));
  assertEquals("rojOut", parsedJSON.get("security_domain"));
  assertEquals("0x81000033", parsedJSON.get("event_code"));
  assertEquals("auth", parsedJSON.get("event_type"));
  assertEquals("notice", parsedJSON.get("severity"));
  assertEquals("login", parsedJSON.get("event_subtype"));
  assertEquals(null, parsedJSON.get("username"));
  assertEquals(null, parsedJSON.get("ip_src_addr"));
}

代码示例来源:origin: org.hibernate.validator/hibernate-validator

@Override
protected Year getReferenceValue(Clock reference) {
  return Year.now( reference );
}

代码示例来源:origin: apache/metron

@Test
public void testParseLoginLine() throws Exception {
  
  //Set up parser, parse message
  GrokWebSphereParser parser = new GrokWebSphereParser();
  parser.configure(parserConfig);
  String testString = "<133>Apr 15 17:47:28 ABCXML1413 [rojOut][0x81000033][auth][notice] user(rick007): "
      + "[120.43.200.6]: User logged into 'cohlOut'.";
  Optional<MessageParserResult<JSONObject>> resultOptional = parser.parseOptionalResult(testString.getBytes());
  Assert.assertNotNull(resultOptional);
  Assert.assertTrue(resultOptional.isPresent());
  List<JSONObject> result = resultOptional.get().getMessages();
  JSONObject parsedJSON = result.get(0);
  long expectedTimestamp = ZonedDateTime.of(Year.now(UTC).getValue(), 4, 15, 17, 47, 28, 0, UTC).toInstant().toEpochMilli();
  //Compare fields
  assertEquals(133, parsedJSON.get("priority"));
  assertEquals(expectedTimestamp, parsedJSON.get("timestamp"));
  assertEquals("ABCXML1413", parsedJSON.get("hostname"));
  assertEquals("rojOut", parsedJSON.get("security_domain"));
  assertEquals("0x81000033", parsedJSON.get("event_code"));
  assertEquals("auth", parsedJSON.get("event_type"));
  assertEquals("notice", parsedJSON.get("severity"));
  assertEquals("login", parsedJSON.get("event_subtype"));
  assertEquals("rick007", parsedJSON.get("username"));
  assertEquals("120.43.200.6", parsedJSON.get("ip_src_addr"));
}

代码示例来源:origin: org.hibernate.validator/hibernate-validator

@Override
protected Year getReferenceValue(Clock reference) {
  return Year.now( reference );
}

代码示例来源:origin: Yorubaname/yorubaname-website

public static CharSequence year() {
    return Year.now().toString();
  }
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Test
public void testJavaYear() throws Exception {
  java.time.Year value = java.time.Year.now();
  java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles");
  newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.Year>(value),  java.time.Year.class, new JavaZoneIdProperty(zoneId));
  newFieldMapperAndMapToPS(NullGetter.<Object,  java.time.Year>getter(), java.time.Year.class);
  verify(ps).setDate(1, new java.sql.Date(value.atMonthDay(MonthDay.of(Month.JANUARY, 1)).atStartOfDay(zoneId).toInstant().toEpochMilli()));
  verify(ps).setNull(2, Types.DATE);
}
//IFJAVA8_END

代码示例来源:origin: org.apache.jmeter/ApacheJMeter_functions

private DateTimeFormatter createFormatter(LocaleFormatObject format) {
  log.debug("Create a new instance of DateTimeFormatter for format '{}' in the cache", format);
  return new DateTimeFormatterBuilder().appendPattern(format.getFormat())
      .parseDefaulting(ChronoField.DAY_OF_MONTH, 1).parseDefaulting(ChronoField.MONTH_OF_YEAR, 1)
      .parseDefaulting(ChronoField.YEAR_OF_ERA, Year.now().getValue()).toFormatter(format.getLocale());
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Test
public void testCharacterToTime() throws Exception {
  testConvertFromCharSequence(Instant.now(), DateTimeFormatter.ISO_INSTANT);
  testConvertFromCharSequence(LocalDate.now(), DateTimeFormatter.ISO_LOCAL_DATE);
  testConvertFromCharSequence(LocalDateTime.now(), DateTimeFormatter.ISO_LOCAL_DATE_TIME);
  testConvertFromCharSequence(LocalTime.now(), DateTimeFormatter.ISO_LOCAL_TIME);
  testConvertFromCharSequence(OffsetDateTime.now(), DateTimeFormatter.ISO_OFFSET_DATE_TIME);
  testConvertFromCharSequence(OffsetTime.now(), DateTimeFormatter.ISO_OFFSET_TIME);
  testConvertFromCharSequence(Year.now(), DateTimeFormatter.ofPattern("yyyy"));
  testConvertFromCharSequence(YearMonth.now(), DateTimeFormatter.ofPattern("yyyy-MM"));
  testConvertFromCharSequence(ZonedDateTime.now(), DateTimeFormatter.ISO_ZONED_DATE_TIME);
}

代码示例来源:origin: org.apache.jmeter/ApacheJMeter_functions

private DateTimeFormatter createFormatter(LocaleFormatObject format) {
  log.debug("Create a new instance of DateTimeFormatter for format '{}' in the cache", format);
  return new DateTimeFormatterBuilder().appendPattern(format.getFormat())
      .parseDefaulting(ChronoField.NANO_OF_SECOND, 0)
      .parseDefaulting(ChronoField.MILLI_OF_SECOND, 0)
      .parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0)
      .parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0)
      .parseDefaulting(ChronoField.HOUR_OF_DAY, 0)
      .parseDefaulting(ChronoField.DAY_OF_MONTH, 1)
      .parseDefaulting(ChronoField.MONTH_OF_YEAR, 1)
      .parseDefaulting(ChronoField.YEAR_OF_ERA, Year.now().getValue())
      .toFormatter(format.getLocale());
}

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