org.joda.time.YearMonth.<init>()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(155)

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

YearMonth.<init>介绍

[英]Constructs a YearMonth with the current year-month, using ISOChronology in the default zone to extract the fields.

The constructor uses the default time zone, resulting in the local time being initialised. Once the constructor is complete, all further calculations are performed without reference to a time-zone (by switching to UTC).
[中]使用默认区域中的等时线来提取字段,用当前的年-月构造一个年-月。
构造函数使用默认时区,从而初始化本地时间。一旦构造完成,所有进一步的计算都将在不参考时区的情况下执行(通过切换到UTC)。

代码示例

代码示例来源:origin: joda-time/joda-time

  1. /**
  2. * Obtains a {@code YearMonth} set to the current system millisecond time
  3. * using <code>ISOChronology</code> in the default time zone.
  4. * The resulting object does not use the zone.
  5. *
  6. * @return the current year-month, not null
  7. * @since 2.0
  8. */
  9. public static YearMonth now() {
  10. return new YearMonth();
  11. }

代码示例来源:origin: JodaOrg/joda-time

  1. /**
  2. * Obtains a {@code YearMonth} set to the current system millisecond time
  3. * using <code>ISOChronology</code> in the default time zone.
  4. * The resulting object does not use the zone.
  5. *
  6. * @return the current year-month, not null
  7. * @since 2.0
  8. */
  9. public static YearMonth now() {
  10. return new YearMonth();
  11. }

代码示例来源:origin: joda-time/joda-time

  1. /**
  2. * Obtains a {@code YearMonth} set to the current system millisecond time
  3. * using the specified chronology.
  4. * The resulting object does not use the zone.
  5. *
  6. * @param chronology the chronology, not null
  7. * @return the current year-month, not null
  8. * @since 2.0
  9. */
  10. public static YearMonth now(Chronology chronology) {
  11. if (chronology == null) {
  12. throw new NullPointerException("Chronology must not be null");
  13. }
  14. return new YearMonth(chronology);
  15. }

代码示例来源:origin: joda-time/joda-time

  1. /**
  2. * Obtains a {@code YearMonth} set to the current system millisecond time
  3. * using <code>ISOChronology</code> in the specified time zone.
  4. * The resulting object does not use the zone.
  5. *
  6. * @param zone the time zone, not null
  7. * @return the current year-month, not null
  8. * @since 2.0
  9. */
  10. public static YearMonth now(DateTimeZone zone) {
  11. if (zone == null) {
  12. throw new NullPointerException("Zone must not be null");
  13. }
  14. return new YearMonth(zone);
  15. }

代码示例来源:origin: JodaOrg/joda-time

  1. /**
  2. * Obtains a {@code YearMonth} set to the current system millisecond time
  3. * using the specified chronology.
  4. * The resulting object does not use the zone.
  5. *
  6. * @param chronology the chronology, not null
  7. * @return the current year-month, not null
  8. * @since 2.0
  9. */
  10. public static YearMonth now(Chronology chronology) {
  11. if (chronology == null) {
  12. throw new NullPointerException("Chronology must not be null");
  13. }
  14. return new YearMonth(chronology);
  15. }

代码示例来源:origin: JodaOrg/joda-time

  1. /**
  2. * Obtains a {@code YearMonth} set to the current system millisecond time
  3. * using <code>ISOChronology</code> in the specified time zone.
  4. * The resulting object does not use the zone.
  5. *
  6. * @param zone the time zone, not null
  7. * @return the current year-month, not null
  8. * @since 2.0
  9. */
  10. public static YearMonth now(DateTimeZone zone) {
  11. if (zone == null) {
  12. throw new NullPointerException("Zone must not be null");
  13. }
  14. return new YearMonth(zone);
  15. }

代码示例来源:origin: joda-time/joda-time

  1. /**
  2. * Constructs a YearMonth from a <code>java.util.Date</code>
  3. * using exactly the same field values avoiding any time zone effects.
  4. * <p>
  5. * Each field is queried from the Date and assigned to the YearMonth.
  6. * <p>
  7. * This factory method always creates a YearMonth with ISO chronology.
  8. *
  9. * @param date the Date to extract fields from
  10. * @return the created YearMonth, never null
  11. * @throws IllegalArgumentException if the calendar is null
  12. * @throws IllegalArgumentException if the year or month is invalid for the ISO chronology
  13. */
  14. @SuppressWarnings("deprecation")
  15. public static YearMonth fromDateFields(Date date) {
  16. if (date == null) {
  17. throw new IllegalArgumentException("The date must not be null");
  18. }
  19. return new YearMonth(date.getYear() + 1900, date.getMonth() + 1);
  20. }

代码示例来源:origin: joda-time/joda-time

  1. /**
  2. * Parses a {@code YearMonth} from the specified string using a formatter.
  3. *
  4. * @param str the string to parse, not null
  5. * @param formatter the formatter to use, not null
  6. * @since 2.0
  7. */
  8. public static YearMonth parse(String str, DateTimeFormatter formatter) {
  9. LocalDate date = formatter.parseLocalDate(str);
  10. return new YearMonth(date.getYear(), date.getMonthOfYear());
  11. }

代码示例来源:origin: JodaOrg/joda-time

  1. /**
  2. * Parses a {@code YearMonth} from the specified string using a formatter.
  3. *
  4. * @param str the string to parse, not null
  5. * @param formatter the formatter to use, not null
  6. * @since 2.0
  7. */
  8. public static YearMonth parse(String str, DateTimeFormatter formatter) {
  9. LocalDate date = formatter.parseLocalDate(str);
  10. return new YearMonth(date.getYear(), date.getMonthOfYear());
  11. }

代码示例来源:origin: joda-time/joda-time

  1. /**
  2. * Sets this field in a copy of the YearMonth.
  3. * <p>
  4. * The YearMonth attached to this property is unchanged by this call.
  5. * Instead, a new instance is returned.
  6. *
  7. * @param value the value to set the field in the copy to
  8. * @return a copy of the YearMonth with the field value changed
  9. * @throws IllegalArgumentException if the value isn't valid
  10. */
  11. public YearMonth setCopy(int value) {
  12. int[] newValues = iBase.getValues();
  13. newValues = getField().set(iBase, iFieldIndex, newValues, value);
  14. return new YearMonth(iBase, newValues);
  15. }

代码示例来源:origin: JodaOrg/joda-time

  1. /**
  2. * Sets this field in a copy of the YearMonth.
  3. * <p>
  4. * The YearMonth attached to this property is unchanged by this call.
  5. * Instead, a new instance is returned.
  6. *
  7. * @param value the value to set the field in the copy to
  8. * @return a copy of the YearMonth with the field value changed
  9. * @throws IllegalArgumentException if the value isn't valid
  10. */
  11. public YearMonth setCopy(int value) {
  12. int[] newValues = iBase.getValues();
  13. newValues = getField().set(iBase, iFieldIndex, newValues, value);
  14. return new YearMonth(iBase, newValues);
  15. }

代码示例来源:origin: joda-time/joda-time

  1. /**
  2. * Sets this field in a copy of the YearMonth to a parsed text value.
  3. * <p>
  4. * The YearMonth attached to this property is unchanged by this call.
  5. * Instead, a new instance is returned.
  6. *
  7. * @param text the text value to set
  8. * @param locale optional locale to use for selecting a text symbol
  9. * @return a copy of the YearMonth with the field value changed
  10. * @throws IllegalArgumentException if the text value isn't valid
  11. */
  12. public YearMonth setCopy(String text, Locale locale) {
  13. int[] newValues = iBase.getValues();
  14. newValues = getField().set(iBase, iFieldIndex, newValues, text, locale);
  15. return new YearMonth(iBase, newValues);
  16. }

代码示例来源:origin: JodaOrg/joda-time

  1. /**
  2. * Sets this field in a copy of the YearMonth to a parsed text value.
  3. * <p>
  4. * The YearMonth attached to this property is unchanged by this call.
  5. * Instead, a new instance is returned.
  6. *
  7. * @param text the text value to set
  8. * @param locale optional locale to use for selecting a text symbol
  9. * @return a copy of the YearMonth with the field value changed
  10. * @throws IllegalArgumentException if the text value isn't valid
  11. */
  12. public YearMonth setCopy(String text, Locale locale) {
  13. int[] newValues = iBase.getValues();
  14. newValues = getField().set(iBase, iFieldIndex, newValues, text, locale);
  15. return new YearMonth(iBase, newValues);
  16. }

代码示例来源:origin: joda-time/joda-time

  1. /**
  2. * Adds to the value of this field in a copy of this YearMonth.
  3. * <p>
  4. * The value will be added to this field. If the value is too large to be
  5. * added solely to this field then it will affect larger fields.
  6. * Smaller fields are unaffected.
  7. * <p>
  8. * If the result would be too large, beyond the maximum year, then an
  9. * IllegalArgumentException is thrown.
  10. * <p>
  11. * The YearMonth attached to this property is unchanged by this call.
  12. * Instead, a new instance is returned.
  13. *
  14. * @param valueToAdd the value to add to the field in the copy
  15. * @return a copy of the YearMonth with the field value changed
  16. * @throws IllegalArgumentException if the value isn't valid
  17. */
  18. public YearMonth addToCopy(int valueToAdd) {
  19. int[] newValues = iBase.getValues();
  20. newValues = getField().add(iBase, iFieldIndex, newValues, valueToAdd);
  21. return new YearMonth(iBase, newValues);
  22. }

代码示例来源:origin: joda-time/joda-time

  1. /**
  2. * Returns a copy of this year-month with the year field updated.
  3. * <p>
  4. * YearMonth is immutable, so there are no set methods.
  5. * Instead, this method returns a new instance with the value of
  6. * year changed.
  7. *
  8. * @param year the year to set
  9. * @return a copy of this object with the field set, never null
  10. * @throws IllegalArgumentException if the value is invalid
  11. */
  12. public YearMonth withYear(int year) {
  13. int[] newValues = getValues();
  14. newValues = getChronology().year().set(this, YEAR, newValues, year);
  15. return new YearMonth(this, newValues);
  16. }

代码示例来源:origin: joda-time/joda-time

  1. /**
  2. * Returns a copy of this year-month with the month of year field updated.
  3. * <p>
  4. * YearMonth is immutable, so there are no set methods.
  5. * Instead, this method returns a new instance with the value of
  6. * month of year changed.
  7. *
  8. * @param monthOfYear the month of year to set
  9. * @return a copy of this object with the field set, never null
  10. * @throws IllegalArgumentException if the value is invalid
  11. */
  12. public YearMonth withMonthOfYear(int monthOfYear) {
  13. int[] newValues = getValues();
  14. newValues = getChronology().monthOfYear().set(this, MONTH_OF_YEAR, newValues, monthOfYear);
  15. return new YearMonth(this, newValues);
  16. }

代码示例来源:origin: JodaOrg/joda-time

  1. /**
  2. * Returns a copy of this year-month with the year field updated.
  3. * <p>
  4. * YearMonth is immutable, so there are no set methods.
  5. * Instead, this method returns a new instance with the value of
  6. * year changed.
  7. *
  8. * @param year the year to set
  9. * @return a copy of this object with the field set, never null
  10. * @throws IllegalArgumentException if the value is invalid
  11. */
  12. public YearMonth withYear(int year) {
  13. int[] newValues = getValues();
  14. newValues = getChronology().year().set(this, YEAR, newValues, year);
  15. return new YearMonth(this, newValues);
  16. }

代码示例来源:origin: JodaOrg/joda-time

  1. /**
  2. * Returns a copy of this year-month with the month of year field updated.
  3. * <p>
  4. * YearMonth is immutable, so there are no set methods.
  5. * Instead, this method returns a new instance with the value of
  6. * month of year changed.
  7. *
  8. * @param monthOfYear the month of year to set
  9. * @return a copy of this object with the field set, never null
  10. * @throws IllegalArgumentException if the value is invalid
  11. */
  12. public YearMonth withMonthOfYear(int monthOfYear) {
  13. int[] newValues = getValues();
  14. newValues = getChronology().monthOfYear().set(this, MONTH_OF_YEAR, newValues, monthOfYear);
  15. return new YearMonth(this, newValues);
  16. }

代码示例来源:origin: joda-time/joda-time

  1. /**
  2. * Handle broken serialization from other tools.
  3. * @return the resolved object, not null
  4. */
  5. private Object readResolve() {
  6. if (DateTimeZone.UTC.equals(getChronology().getZone()) == false) {
  7. return new YearMonth(this, getChronology().withUTC());
  8. }
  9. return this;
  10. }

代码示例来源:origin: JodaOrg/joda-time

  1. /**
  2. * Handle broken serialization from other tools.
  3. * @return the resolved object, not null
  4. */
  5. private Object readResolve() {
  6. if (DateTimeZone.UTC.equals(getChronology().getZone()) == false) {
  7. return new YearMonth(this, getChronology().withUTC());
  8. }
  9. return this;
  10. }

相关文章