gpt4 book ai didi

org.threeten.bp.YearMonth类的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 13:27:31 32 4
gpt4 key购买 nike

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

val yearMonth = new YearMonth();
val formatter = DateTimeFormat.forPattern("yyyyMM");
val dates = (0 to 5).map {
  i=>formatter.print(yearMonth.plusMonths(i)).toInt 
}.toList

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

YearMonth ym = YearMonth.of(2000, 2);
System.out.println(ym.lengthOfMonth()); //29 as expected

代码示例来源:origin: org.threeten/threetenbp

/**
 * Combines this year with a month to create a {@code YearMonth}.
 * <p>
 * This returns a {@code YearMonth} formed from this year and the specified month.
 * All possible combinations of year and month are valid.
 * <p>
 * This method can be used as part of a chain to produce a date:
 * <pre>
 *  LocalDate date = year.atMonth(month).atDay(day);
 * </pre>
 *
 * @param month  the month-of-year to use, not null
 * @return the year-month formed from this year and the specified month, not null
 */
public YearMonth atMonth(Month month) {
  return YearMonth.of(year, month);
}

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

YearMonth yearMonth = new YearMonth();
yearMonth.toLocalDate(1).dayOfMonth().getMaximumValue();

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

public List<LocalDate> getDateRange(YearMonth yearMonth){
 List<LocalDate> dateRange = new ArrayList<>();
 IntStream.of(yearMonth.lengthOfMonth()).foreach(day -> dateRange.add(yearMonth.at(day));
 return  dateRange 
}

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

YearMonth ym = new YearMonth();
dt = ym.toDateTime(null);
System.out.println(dt.dayOfMonth().getMaximumValue());

代码示例来源:origin: ThreeTen/threetenbp

f.checkValidValue(newValue);
switch (f) {
  case MONTH_OF_YEAR: return withMonth((int) newValue);
  case PROLEPTIC_MONTH: return plusMonths(newValue - getLong(PROLEPTIC_MONTH));
  case YEAR_OF_ERA: return withYear((int) (year < 1 ? 1 - newValue : newValue));
  case YEAR: return withYear((int) newValue);
  case ERA: return (getLong(ERA) == newValue ? this : withYear(1 - year));

代码示例来源:origin: com.github.joschi.jackson/jackson-datatype-threetenbp

@Override
public void serialize(YearMonth yearMonth, JsonGenerator generator, SerializerProvider provider) throws IOException
{
  if (useTimestamp(provider)) {
    generator.writeStartArray();
    generator.writeNumber(yearMonth.getYear());
    generator.writeNumber(yearMonth.getMonthValue());
    generator.writeEndArray();
  } else {
    String str = (_formatter == null) ? yearMonth.toString() : yearMonth.format(_formatter);
    generator.writeString(str);
  }
}

代码示例来源:origin: org.threeten/threetenbp

YearMonth end = YearMonth.from(endExclusive);
if (unit instanceof ChronoUnit) {
  long monthsUntil = end.getProlepticMonth() - getProlepticMonth();  // no overflow
  switch ((ChronoUnit) unit) {
    case MONTHS: return monthsUntil;
    case CENTURIES: return monthsUntil / 1200;
    case MILLENNIA: return monthsUntil / 12000;
    case ERAS: return end.getLong(ERA) - getLong(ERA);

代码示例来源:origin: com.github.joschi.jackson/jackson-datatype-threetenbp

return YearMonth.parse(string, _formatter);
} catch (DateTimeException e) {
  _rethrowDateTimeException(parser, context, e, string);
      "Expected array to end.");
return YearMonth.of(year, month);

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

import org.joda.time.YearMonth;
import java.util.Locale;

public class X {

  public static void main(String[] s){
    for (int i = 1;i<13; i++) {
      YearMonth md = new YearMonth(1992, i);
      System.out.println(md.monthOfYear().getAsText(new Locale("ru")));
    }
  }
}

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

YearMonth yearMonth = new YearMonth (1970, 1);
 Interval interval = yearMonth.toInterval(DateTimeZone.UTC);
 int startSSE = (int) TimeUnit.MILLISECONDS.toSeconds(interval.getStartMillis());
 int   endSSE = (int) TimeUnit.MILLISECONDS.toSeconds(interval.getEndMillis());
 System.out.printf("%d -> %d (%4.6f days)\n", startSSE, endSSE, ((float)(endSSE-startSSE))/(24*60*60));

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

public static void main(String[] args) {
  System.out.println(mapToCurrentCentury(16, 11));
  System.out.println(mapToCurrentCentury(116, 11));
  System.out.println(mapToCurrentCentury(1116, 11));
}

private static YearMonth mapToCurrentCentury(int year, int month) {
  if(year < 1000) {
    YearMonth now = YearMonth.now();
    return now.withYear(((now.get(ChronoField.YEAR) / 1000) * 1000) + (year % 1000)).withMonth(month);
  }
  else {
    return YearMonth.of(year, month);
  }
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Obtains an instance of {@code YearMonth} from a text string such as {@code 2007-12}.
 * <p>
 * The string must represent a valid year-month.
 * The format must be {@code yyyy-MM}.
 * Years outside the range 0000 to 9999 must be prefixed by the plus or minus symbol.
 *
 * @param text  the text to parse such as "2007-12", not null
 * @return the parsed year-month, not null
 * @throws DateTimeParseException if the text cannot be parsed
 */
public static YearMonth parse(CharSequence text) {
  return parse(text, PARSER);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Gets the range of valid values for the specified field.
 * <p>
 * The range object expresses the minimum and maximum valid values for a field.
 * This year-month is used to enhance the accuracy of the returned range.
 * If it is not possible to return the range, because the field is not supported
 * or for some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the query is implemented here.
 * The {@link #isSupported(TemporalField) supported fields} will return
 * appropriate range instances.
 * All other {@code ChronoField} instances will throw a {@code DateTimeException}.
 * <p>
 * If the field is not a {@code ChronoField}, then the result of this method
 * is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)}
 * passing {@code this} as the argument.
 * Whether the range can be obtained is determined by the field.
 *
 * @param field  the field to query the range for, not null
 * @return the range of valid values for the field, not null
 * @throws DateTimeException if the range for the field cannot be obtained
 */
@Override
public ValueRange range(TemporalField field) {
  if (field == YEAR_OF_ERA) {
    return (getYear() <= 0 ? ValueRange.of(1, Year.MAX_VALUE + 1) : ValueRange.of(1, Year.MAX_VALUE));
  }
  return super.range(field);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Is this year-month after the specified year-month.
 *
 * @param other  the other year-month to compare to, not null
 * @return true if this is after the specified year-month
 */
public boolean isAfter(YearMonth other) {
  return compareTo(other) > 0;
}

代码示例来源:origin: ThreeTen/threetenbp

@Override
  public YearMonth queryFrom(TemporalAccessor temporal) {
    return YearMonth.from(temporal);
  }
};

代码示例来源:origin: org.threeten/threetenbp

f.checkValidValue(newValue);
switch (f) {
  case MONTH_OF_YEAR: return withMonth((int) newValue);
  case PROLEPTIC_MONTH: return plusMonths(newValue - getLong(PROLEPTIC_MONTH));
  case YEAR_OF_ERA: return withYear((int) (year < 1 ? 1 - newValue : newValue));
  case YEAR: return withYear((int) newValue);
  case ERA: return (getLong(ERA) == newValue ? this : withYear(1 - year));

代码示例来源:origin: ThreeTen/threetenbp

YearMonth end = YearMonth.from(endExclusive);
if (unit instanceof ChronoUnit) {
  long monthsUntil = end.getProlepticMonth() - getProlepticMonth();  // no overflow
  switch ((ChronoUnit) unit) {
    case MONTHS: return monthsUntil;
    case CENTURIES: return monthsUntil / 1200;
    case MILLENNIA: return monthsUntil / 12000;
    case ERAS: return end.getLong(ERA) - getLong(ERA);

代码示例来源:origin: org.threeten/threetenbp

/**
 * Obtains an instance of {@code YearMonth} from a text string such as {@code 2007-12}.
 * <p>
 * The string must represent a valid year-month.
 * The format must be {@code yyyy-MM}.
 * Years outside the range 0000 to 9999 must be prefixed by the plus or minus symbol.
 *
 * @param text  the text to parse such as "2007-12", not null
 * @return the parsed year-month, not null
 * @throws DateTimeParseException if the text cannot be parsed
 */
public static YearMonth parse(CharSequence text) {
  return parse(text, PARSER);
}

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