< prev index next >

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

Print this page
rev 17464 : [mq]: 8184314
   1 /*
   2  * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  83 import java.time.temporal.TemporalAccessor;
  84 import java.time.temporal.TemporalAdjuster;
  85 import java.time.temporal.TemporalAmount;
  86 import java.time.temporal.TemporalField;
  87 import java.time.temporal.TemporalQueries;
  88 import java.time.temporal.TemporalQuery;
  89 import java.time.temporal.TemporalUnit;
  90 import java.time.temporal.UnsupportedTemporalTypeException;
  91 import java.time.temporal.ValueRange;
  92 import java.time.zone.ZoneRules;
  93 import java.util.Comparator;
  94 import java.util.Objects;
  95 
  96 /**
  97  * A date-time with an offset from UTC/Greenwich in the ISO-8601 calendar system,
  98  * such as {@code 2007-12-03T10:15:30+01:00}.
  99  * <p>
 100  * {@code OffsetDateTime} is an immutable representation of a date-time with an offset.
 101  * This class stores all date and time fields, to a precision of nanoseconds,
 102  * as well as the offset from UTC/Greenwich. For example, the value
 103  * "2nd October 2007 at 13:45.30.123456789 +02:00" can be stored in an {@code OffsetDateTime}.
 104  * <p>
 105  * {@code OffsetDateTime}, {@link java.time.ZonedDateTime} and {@link java.time.Instant} all store an instant
 106  * on the time-line to nanosecond precision.
 107  * {@code Instant} is the simplest, simply representing the instant.
 108  * {@code OffsetDateTime} adds to the instant the offset from UTC/Greenwich, which allows
 109  * the local date-time to be obtained.
 110  * {@code ZonedDateTime} adds full time-zone rules.
 111  * <p>
 112  * It is intended that {@code ZonedDateTime} or {@code Instant} is used to model data
 113  * in simpler applications. This class may be used when modeling date-time concepts in
 114  * more detail, or when communicating to a database or in a network protocol.
 115  *
 116  * <p>
 117  * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
 118  * class; use of identity-sensitive operations (including reference equality
 119  * ({@code ==}), identity hash code, or synchronization) on instances of
 120  * {@code OffsetDateTime} may have unpredictable results and should be avoided.
 121  * The {@code equals} method should be used for comparisons.
 122  *
 123  * @implSpec


   1 /*
   2  * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  83 import java.time.temporal.TemporalAccessor;
  84 import java.time.temporal.TemporalAdjuster;
  85 import java.time.temporal.TemporalAmount;
  86 import java.time.temporal.TemporalField;
  87 import java.time.temporal.TemporalQueries;
  88 import java.time.temporal.TemporalQuery;
  89 import java.time.temporal.TemporalUnit;
  90 import java.time.temporal.UnsupportedTemporalTypeException;
  91 import java.time.temporal.ValueRange;
  92 import java.time.zone.ZoneRules;
  93 import java.util.Comparator;
  94 import java.util.Objects;
  95 
  96 /**
  97  * A date-time with an offset from UTC/Greenwich in the ISO-8601 calendar system,
  98  * such as {@code 2007-12-03T10:15:30+01:00}.
  99  * <p>
 100  * {@code OffsetDateTime} is an immutable representation of a date-time with an offset.
 101  * This class stores all date and time fields, to a precision of nanoseconds,
 102  * as well as the offset from UTC/Greenwich. For example, the value
 103  * "2nd October 2007 at 13:45:30.123456789 +02:00" can be stored in an {@code OffsetDateTime}.
 104  * <p>
 105  * {@code OffsetDateTime}, {@link java.time.ZonedDateTime} and {@link java.time.Instant} all store an instant
 106  * on the time-line to nanosecond precision.
 107  * {@code Instant} is the simplest, simply representing the instant.
 108  * {@code OffsetDateTime} adds to the instant the offset from UTC/Greenwich, which allows
 109  * the local date-time to be obtained.
 110  * {@code ZonedDateTime} adds full time-zone rules.
 111  * <p>
 112  * It is intended that {@code ZonedDateTime} or {@code Instant} is used to model data
 113  * in simpler applications. This class may be used when modeling date-time concepts in
 114  * more detail, or when communicating to a database or in a network protocol.
 115  *
 116  * <p>
 117  * This is a <a href="{@docRoot}/java/lang/doc-files/ValueBased.html">value-based</a>
 118  * class; use of identity-sensitive operations (including reference equality
 119  * ({@code ==}), identity hash code, or synchronization) on instances of
 120  * {@code OffsetDateTime} may have unpredictable results and should be avoided.
 121  * The {@code equals} method should be used for comparisons.
 122  *
 123  * @implSpec


< prev index next >