< prev index next >

src/java.base/share/classes/java/time/YearMonth.java

Print this page

 100 import java.util.Objects;
 101 
 102 /**
 103  * A year-month in the ISO-8601 calendar system, such as {@code 2007-12}.
 104  * <p>
 105  * {@code YearMonth} is an immutable date-time object that represents the combination
 106  * of a year and month. Any field that can be derived from a year and month, such as
 107  * quarter-of-year, can be obtained.
 108  * <p>
 109  * This class does not store or represent a day, time or time-zone.
 110  * For example, the value "October 2007" can be stored in a {@code YearMonth}.
 111  * <p>
 112  * The ISO-8601 calendar system is the modern civil calendar system used today
 113  * in most of the world. It is equivalent to the proleptic Gregorian calendar
 114  * system, in which today's rules for leap years are applied for all time.
 115  * For most applications written today, the ISO-8601 rules are entirely suitable.
 116  * However, any application that makes use of historical dates, and requires them
 117  * to be accurate will find the ISO-8601 approach unsuitable.
 118  * <p>
 119  * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
 120  * class; programmers should treat instances that are
 121  * {@linkplain #equals(Object) equal} as interchangeable and should not
 122  * use instances for synchronization, or unpredictable behavior may
 123  * occur. For example, in a future release, synchronization may fail.
 124  * The {@code equals} method should be used for comparisons.







 125  *
 126  * @implSpec
 127  * This class is immutable and thread-safe.
 128  *
 129  * @since 1.8
 130  */
 131 @jdk.internal.ValueBased

 132 public final class YearMonth
 133         implements Temporal, TemporalAdjuster, Comparable<YearMonth>, Serializable {
 134 
 135     /**
 136      * Serialization version.
 137      */
 138     @java.io.Serial
 139     private static final long serialVersionUID = 4183400860270640070L;
 140     /**
 141      * Parser.
 142      */
 143     private static final DateTimeFormatter PARSER = new DateTimeFormatterBuilder()
 144         .appendValue(YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
 145         .appendLiteral('-')
 146         .appendValue(MONTH_OF_YEAR, 2)
 147         .toFormatter();
 148 
 149     /**
 150      * The year.
 151      */

 100 import java.util.Objects;
 101 
 102 /**
 103  * A year-month in the ISO-8601 calendar system, such as {@code 2007-12}.
 104  * <p>
 105  * {@code YearMonth} is an immutable date-time object that represents the combination
 106  * of a year and month. Any field that can be derived from a year and month, such as
 107  * quarter-of-year, can be obtained.
 108  * <p>
 109  * This class does not store or represent a day, time or time-zone.
 110  * For example, the value "October 2007" can be stored in a {@code YearMonth}.
 111  * <p>
 112  * The ISO-8601 calendar system is the modern civil calendar system used today
 113  * in most of the world. It is equivalent to the proleptic Gregorian calendar
 114  * system, in which today's rules for leap years are applied for all time.
 115  * For most applications written today, the ISO-8601 rules are entirely suitable.
 116  * However, any application that makes use of historical dates, and requires them
 117  * to be accurate will find the ISO-8601 approach unsuitable.
 118  * <p>
 119  * This is a <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>
 120  * class; programmers should treat instances that are {@linkplain #equals(Object) equal}
 121  * as interchangeable and should not use instances for synchronization, mutexes, or
 122  * with {@linkplain java.lang.ref.Reference object references}.
 123  *
 124  * <div class="preview-block">
 125  *      <div class="preview-comment">
 126  *          When preview features are enabled, {@code YearMonth} is a {@linkplain Class#isValue value class}.
 127  *          Use of value class instances for synchronization, mutexes, or with
 128  *          {@linkplain java.lang.ref.Reference object references} result in
 129  *          {@link IdentityException}.
 130  *      </div>
 131  * </div>
 132  *
 133  * @implSpec
 134  * This class is immutable and thread-safe.
 135  *
 136  * @since 1.8
 137  */
 138 @jdk.internal.ValueBased
 139 @jdk.internal.MigratedValueClass
 140 public final class YearMonth
 141         implements Temporal, TemporalAdjuster, Comparable<YearMonth>, Serializable {
 142 
 143     /**
 144      * Serialization version.
 145      */
 146     @java.io.Serial
 147     private static final long serialVersionUID = 4183400860270640070L;
 148     /**
 149      * Parser.
 150      */
 151     private static final DateTimeFormatter PARSER = new DateTimeFormatterBuilder()
 152         .appendValue(YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
 153         .appendLiteral('-')
 154         .appendValue(MONTH_OF_YEAR, 2)
 155         .toFormatter();
 156 
 157     /**
 158      * The year.
 159      */
< prev index next >