gpt4 book ai didi

java.time.YearMonth类的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 01:08:40 31 4
gpt4 key购买 nike

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

YearMonth介绍

[英]A year-month in the ISO-8601 calendar system, such as 2007-12.

YearMonth is an immutable date-time object that represents the combination of a year and month. Any field that can be derived from a year and month, such as quarter-of-year, can be obtained.

This class does not store or represent a day, time or time-zone. For example, the value "October 2007" can be stored in a YearMonth.

The ISO-8601 calendar system is the modern civil calendar system used today in most of the world. It is equivalent to the proleptic Gregorian calendar system, in which today's rules for leap years are applied for all time. For most applications written today, the ISO-8601 rules are entirely suitable. However, any application that makes use of historical dates, and requires them to be accurate will find the ISO-8601 approach unsuitable.

Specification for implementors

This class is immutable and thread-safe.
[中]ISO-8601日历系统中的一年一月,如2007-12。
YearMonth是一个不可变的日期时间对象,表示年和月的组合。可以获得任何可以从一年和一个月派生的字段,例如一年的季度。
此类不存储或表示日期、时间或时区。例如,值“2007年10月”可以存储在YearMonth中。
ISO-8601日历系统是当今世界大部分地区使用的现代民用日历系统。它相当于公历的前身,即今天的闰年规则一直适用。对于今天编写的大多数应用程序,ISO-8601规则完全适用。然而,任何使用历史日期并要求其准确的应用程序都会发现ISO-8601方法不合适。
####实施者规范
这个类是不可变的,是线程安全的。

代码示例

代码示例来源:origin: hibernate/hibernate-orm

@Override
  public YearMonth convertToEntityAttribute(Integer dbData) {
    return YearMonth.of(dbData / 100, dbData % 100);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public YearMonth parse(String text, Locale locale) throws ParseException {
  return YearMonth.parse(text);
}

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

protected void _serializeAsArrayContents(YearMonth value, JsonGenerator g,
    SerializerProvider provider) throws IOException
{
  g.writeNumber(value.getYear());
  g.writeNumber(value.getMonthValue());
}

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

@Override
public void writeObject(ObjectOutput output, YearMonth value) throws IOException {
  output.writeInt(value.getYear());
  DefaultExternalizer.MONTH.cast(Month.class).writeObject(output, value.getMonth());
}

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

@Override
public void serialize(YearMonth value, JsonGenerator g, SerializerProvider provider) throws IOException
{
  if (useTimestamp(provider)) {
    g.writeStartArray();
    _serializeAsArrayContents(value, g, provider);
    g.writeEndArray();
    return;
  }
  g.writeString((_formatter == null) ? value.toString() : value.format(_formatter));
}

代码示例来源:origin: OpenGamma/Strata

public void test_optionIdUnderlying_monthly() {
 SecurityId test = EtdIdUtils.optionId(
   ExchangeIds.ECAG, FGBS, YearMonth.of(2017, 6), MONTHLY, 0, PutCall.PUT, 12.34, YearMonth.of(2017, 9));
 assertEquals(test.getStandardId(), StandardId.of("OG-ETD", "O-ECAG-FGBS-201706-P12.34-U201709"));
}

代码示例来源:origin: OpenGamma/Strata

@Test(dataProvider = "quarterly10th")
public void test_nextOrSameQuarterly10th(LocalDate base, LocalDate expect1, LocalDate expect2, LocalDate expect3) {
 LocalDate date = base.plusDays(1);
 while (!date.isAfter(expect1)) {
  assertEquals(DateSequences.QUARTERLY_10TH.nextOrSame(date), expect1);
  assertEquals(DateSequences.QUARTERLY_10TH.nthOrSame(date, 1), expect1);
  assertEquals(DateSequences.QUARTERLY_10TH.nthOrSame(date, 2), expect2);
  assertEquals(DateSequences.QUARTERLY_10TH.nthOrSame(date, 3), expect3);
  date = date.plusDays(1);
 }
 assertEquals(DateSequences.QUARTERLY_10TH.dateMatching(YearMonth.from(date)), expect1);
}

代码示例来源:origin: OpenGamma/Strata

public void test_metadata_end() {
 IborFutureCurveNode node = IborFutureCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD, LABEL);
 LocalDate date = LocalDate.of(2015, 10, 20);
 LocalDate referenceDate = TEMPLATE.calculateReferenceDateFromTradeDate(date, REF_DATA);
 LocalDate maturityDate = TEMPLATE.getIndex().calculateMaturityFromEffective(referenceDate, REF_DATA);
 ParameterMetadata metadata = node.metadata(date, REF_DATA);
 assertEquals(metadata.getLabel(), LABEL);
 assertTrue(metadata instanceof YearMonthDateParameterMetadata);
 assertEquals(((YearMonthDateParameterMetadata) metadata).getDate(), maturityDate);
 assertEquals(((YearMonthDateParameterMetadata) metadata).getYearMonth(), YearMonth.from(referenceDate));
}

代码示例来源:origin: OpenGamma/Strata

public void test_QUARTERLY_IMM() {
 DateSequence test = DateSequences.QUARTERLY_IMM;
 assertEquals(test.getName(), "Quarterly-IMM");
 assertEquals(test.toString(), "Quarterly-IMM");
 assertEquals(test.dateMatching(YearMonth.of(2013, 3)), LocalDate.of(2013, 3, 20));
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

return GregorianCalendar.from(ot.atDate(LocalDate.ofEpochDay(0)).atZoneSameInstant(ZoneId.systemDefault()));
} catch (final DateTimeParseException e) {
  return GregorianCalendar.from(ot.atDate(LocalDate.ofEpochDay(0)).atZoneSameInstant(ZoneId.systemDefault()));
} catch (final DateTimeParseException e) {
  return GregorianCalendar.from(ot.atDate(LocalDate.ofEpochDay(0)).atZoneSameInstant(ZoneId.systemDefault()));
} catch (final DateTimeParseException e) {
  final Year y = Year.from(ta);
  final MonthDay md = MonthDay.from(ta);
  final OffsetTime ot = OffsetTime.from(ta);
  return GregorianCalendar.from(ot.atDate(y.atMonthDay(md)).atZoneSameInstant(ZoneId.systemDefault()));
} catch (final DateTimeParseException e) {
  final Year y = Year.from(ta);
  final MonthDay md = MonthDay.from(ta);
  final OffsetTime ot = OffsetTime.from(ta);
  final YearMonth ym = YearMonth.parse(str);
  return GregorianCalendar.from(ym.atDay(1).atStartOfDay(ZoneId.systemDefault()));
} catch (final DateTimeParseException e) {

代码示例来源:origin: OpenGamma/Strata

public void test_metadata_last_fixing() {
 IborFutureCurveNode node =
   IborFutureCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD, LABEL).withDate(CurveNodeDate.LAST_FIXING);
 ImmutableMarketData marketData = ImmutableMarketData.builder(VAL_DATE).addValue(QUOTE_ID, 0.0d).build();
 IborFutureTrade trade = node.trade(1d, marketData, REF_DATA);
 LocalDate fixingDate = trade.getProduct().getFixingDate();
 DatedParameterMetadata metadata = node.metadata(VAL_DATE, REF_DATA);
 assertEquals(metadata.getDate(), fixingDate);
 LocalDate referenceDate = TEMPLATE.calculateReferenceDateFromTradeDate(VAL_DATE, REF_DATA);
 assertEquals(((YearMonthDateParameterMetadata) metadata).getYearMonth(), YearMonth.from(referenceDate));
}

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

addExtendedEntry(LocalDate.of(2016, 1, 1), "LocalDate", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(LocalDateTime.of(2016, 1, 1, 12, 30), "LocalDateTime", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(LocalTime.of(12, 30, 45), "LocalTime", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(Period.of(1, 6, 15), "Period", "The following example is a `Period` of one year, six months and fifteen days.", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(new Short("100"), "Short", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(Year.of(2016), "Year", "The following example is of the `Year` \"2016\".", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(YearMonth.of(2016, 6), "YearMonth", "The following example is a `YearMonth` of \"June 2016\"", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(ZonedDateTime.of(2016, 12, 23, 12, 12, 24, 36, ZoneId.of("GMT+2")), "ZonedDateTime", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
addExtendedEntry(ZoneOffset.ofHoursMinutesSeconds(3, 6, 9), "ZoneOffset", "The following example is a `ZoneOffset` of three hours, six minutes, and nine seconds.", Compatibilities.UNTYPED_GRAPHSON.matchToArray());

代码示例来源:origin: jfoenixadmin/JFoenix

int firstOfMonthIndex = selectedYearMonth.get().atDay(1).getDayOfWeek().getValue() - firstDayOfWeek;
firstOfMonthIndex += firstOfMonthIndex < 0 ? daysPerWeek : 0;
YearMonth currentYearMonth = selectedYearMonth.get();
      daysInCurMonth = currentYearMonth.lengthOfMonth();
    LocalDate date = currentYearMonth.atDay(dayIndex);
    dayCellDates[i] = date;
    if (date.equals(LocalDate.now())) {
      dayCell.setTextFill(this.datePicker.getDefaultColor());
      dayCell.getStyleClass().add("today");

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

assertTrue(immutability.test(Duration.ZERO));
assertTrue(immutability.test(Instant.now()));
assertTrue(immutability.test(LocalDate.now()));
assertTrue(immutability.test(LocalDateTime.now()));
assertTrue(immutability.test(LocalTime.now()));
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));
assertTrue(immutability.test(ZoneRules.of(ZoneOffset.UTC).nextTransition(Instant.now())));

代码示例来源:origin: jfoenixadmin/JFoenix

void clearFocus() {
  LocalDate focusDate = datePicker.getValue();
  if (focusDate == null) {
    focusDate = LocalDate.now();
  }
  if (YearMonth.from(focusDate).equals(selectedYearMonth.get())) {
    goToDate(focusDate, true);
  }
}

代码示例来源:origin: stackoverflow.com

// Code for your method.
YearMonth yearMonth = year.atMonth ( month ); // Instantiate a YearMonth from a Year and a Month.
LocalDate localDate = yearMonth.atDay ( 1 ); // First day of month.
ZoneId zoneId = ZoneId.systemDefault (); // Or… ZoneId.of("America/Montreal");
ZonedDateTime zdt = localDate.atStartOfDay ( zoneId );
long millis = zdt.toInstant ().toEpochMilli ();

代码示例来源:origin: jfoenixadmin/JFoenix

protected void updateMonthYearPane() {
  // update date labels
  YearMonth yearMonth = selectedYearMonth.get();
  LocalDate value = datePicker.getValue();
  value = value == null ? LocalDate.now() : value;
  selectedDateLabel.setText(DateTimeFormatter.ofPattern("EEE, MMM dd").format(value));
  selectedYearLabel.setText(formatYear(yearMonth));
  monthYearLabel.setText(formatMonth(yearMonth) + " " + formatYear(yearMonth));
  Chronology chrono = datePicker.getChronology();
  LocalDate firstDayOfMonth = yearMonth.atDay(1);
  backMonthButton.setDisable(!isValidDate(chrono, firstDayOfMonth, -1, DAYS));
  forwardMonthButton.setDisable(!isValidDate(chrono, firstDayOfMonth, +1, MONTHS));
}

代码示例来源:origin: jfoenixadmin/JFoenix

selectedYearMonth.set((date != null) ? YearMonth.from(date) : YearMonth.now());
selectedYearMonth.addListener((observable, oldValue, newValue) -> updateValues());
      goToDate(LocalDate.now(), true);
      event.consume();
      break;

代码示例来源:origin: zsoltherpai/fluent-jdbc

private static void javaTime(Map<Class, ParamSetter> ss) {
  reg(ss, Instant.class, (param, ps, i) -> ps.setTimestamp(i, timestamp(param)));
  reg(ss, OffsetDateTime.class, (param, ps, i) -> ps.setTimestamp(i, timestamp(param.toInstant())));
  reg(ss, ZonedDateTime.class, (param, ps, i) -> ps.setTimestamp(i, timestamp(param.toInstant())));
  reg(ss, LocalDate.class, (param, ps, i) -> ps.setDate(i, java.sql.Date.valueOf(param)));
  reg(ss, LocalTime.class, (param, ps, i) -> ps.setTime(i, java.sql.Time.valueOf(param)));
  reg(ss, LocalDateTime.class, (param, ps, i) -> ps.setTimestamp(i, java.sql.Timestamp.valueOf(param)));
  reg(ss, Year.class, (param, ps, i) -> ps.setDate(i, java.sql.Date.valueOf(LocalDate.of(param.getValue(), Month.JANUARY, 1))));
  reg(ss, YearMonth.class, (param, ps, i) -> ps.setDate(i, java.sql.Date.valueOf(LocalDate.of(param.getYear(), param.getMonth(), 1))));
}

代码示例来源:origin: ebean-orm/ebean

protected LocalDate toLocalDate(YearMonth yearMonth) {
 return LocalDate.of(yearMonth.getYear(), yearMonth.getMonth(), 1);
}

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