The {@link #valueOf} method can convert strings such as "3.5 minutes", "5hours", into Duration instances. The recognized units of time are the "millisecond", "second", "minute" "hour" and "day". The unit name may be followed by an "s". Thus, "2 day" and "2 days" are equivalent. In the absence of a time unit specification, milliseconds are assumed. @author Ceki Gulcu
Duration
are the following:Trip
defines the travel from the information sign to the announced location. duration
is the duration displayed by the sign (in minutes). A duration is defined by a fixed number of milliseconds. There is no concept of fields, such as days or seconds, as these fields can vary in length. A duration may be converted to a {@link Period} to obtain field values.This conversion will typically cause a loss of precision however.
Duration is thread-safe and immutable. @author Brian S O'Neill @author Stephen Colebourne @since 1.0
Duration class.
Strings that can be parsed consist of value/unit pairs. Values can be arbitrary text, valid unit names are "years", "yrs", "months", "mts", "hours", "hrs", "min" and "sec". There may be only one pair for each unit i.e. "5 years 3 yrs" is illegal.
Value/unit pairs must be separated from each other with at least one whitespace character. Units may follow values immediately if the value is a number, else they must be separated by at least one whitespace.
Any duration unit may be omitted, but the descending order of units must be preserved.
Parsing is done in two phases. First, during parse
the value/unit pairs are identified and the values are stored as strings. This allows the class even to be used when the values are expressions that must be evaluated. If this feature is used, the evaluation must be performed by retrieving the string values (using "...AsParsed
"), evaluating the expression and setting the result.
Duration
will try to convert the parsed string to a number only if a unit is accessed and has not been set explicitly. Thus, all accessor methods may throw a NumberFormatException
even if parse
has not thrown a ParseException
.
@author Michael Lipp
@version $Revision: 2368 $
Duration represents time periods which have values independent of the context. So, whilst we can't say how long a month is without knowing the year and the name of the month, we know how long a day is independent of the date.
This is not 100% true for days. Days can actually be 23, 24 or 25 hours long (due to daylight saving adjustments.)
If you ask Duration to convert itself to milliseconds then it will work on the basis of 24 hours in a day. If you add or subtract it from a date it will take daylight saving into account.
@author John Wilson tug@wilson.co.ukThis class models a quantity or amount of time in terms of seconds and nanoseconds. It can be accessed using other duration-based units, such as minutes and hours. In addition, the {@link ChronoUnit#DAYS DAYS} unit can be used and is treated asexactly equal to 24 hours, thus ignoring daylight savings effects. See {@link Period} for the date-based equivalent to this class.
A physical duration could be of infinite length. For practicality, the duration is stored with constraints similar to {@link Instant}. The duration uses nanosecond resolution with a maximum value of the seconds that can be held in a {@code long}. This is greater than the current estimated age of the universe.
The range of a duration requires the storage of a number larger than a {@code long}. To achieve this, the class stores a {@code long} representing seconds and an {@code int}representing nanosecond-of-second, which will always be between 0 and 999,999,999. The model is of a directed duration, meaning that the duration may be negative.
The duration is measured in "seconds", but these are not necessarily identical to the scientific "SI second" definition based on atomic clocks. This difference only impacts durations measured near a leap-second and should not affect most applications. See {@link Instant} for a discussion as to the meaning of the second and time-scales.
This is a value-based class; use of identity-sensitive operations (including reference equality ( {@code ==}), identity hash code, or synchronization) on instances of {@code Duration} may have unpredictable results and should be avoided.The {@code equals} method should be used for comparisons. @implSpec This class is immutable and thread-safe. @since 1.8
The Time Framework for Java models time as a series of instantaneous events, known as {@link Instant instants}, along a single time-line. This class represents the duration between two of those instants.
A physical instant is an instantaneous event. However, for practicality the API and this class uses a precision of nanoseconds.
A physical duration could be of infinite length. However, for practicality the API and this class limits the length to the number of seconds that can be held in a {@code long}.
In order to represent the data a 96 bit number is required. To achieve this the data is stored as seconds, measured using a {@code long}, and nanoseconds, measured using an {@code int}. The nanosecond part will always be between 0 and 999,999,999 representing the nanosecond part of the second. For example, the negative duration of {@code PT-0.1S} is represented as-1 second and 900,000,000 nanoseconds.
In this API, the unit of "seconds" only has a precise meaning when applied to an instant. This is because it is the instant that defines the time scale used, not the duration. For example, the simplified UTC time scale used by {@code Instant} ignores leap seconds,which alters the effective length of a second. By comparison, the TAI time scale follows the international scientific definition of a second exactly. For most applications, this subtlety will be irrelevant.
Duration is immutable and thread-safe. @author Michael Nascimento Santos @author Stephen Colebourne
Immutable representation of a time span as defined in the W3C XML Schema 1.0 specification.
A Duration object represents a period of Gregorian time, which consists of six fields (years, months, days, hours, minutes, and seconds) plus a sign (+/-) field.
The first five fields have non-negative (>=0) integers or null (which represents that the field is not set), and the seconds field has a non-negative decimal or null. A negative sign indicates a negative duration.
This class provides a number of methods that make it easy to use for the duration datatype of XML Schema 1.0 with the errata.
Duration objects only have partial order, where two values A and B maybe either:
For example, 30 days cannot be meaningfully compared to one month. The {@link #compare(Duration duration)} method implements thisrelationship.
See the {@link #isLongerThan(Duration)} method for details aboutthe order relationship among Duration
objects.
This class provides a set of basic arithmetic operations, such as addition, subtraction and multiplication. Because durations don't have total order, an operation could fail for some combinations of operations. For example, you cannot subtract 15 days from 1 month. See the javadoc of those methods for detailed conditions where this could happen.
Also, division of a duration by a number is not provided because the Duration
class can only deal with finite precision decimal numbers. For example, one cannot represent 1 sec divided by 3.
However, you could substitute a division by 3 with multiplying by numbers such as 0.3 or 0.333.
Because some operations of Duration
rely on {@link Calendar}even though {@link Duration} can hold very large or very small values,some of the methods may not work correctly on such Duration
s. The impacted methods document their dependency on {@link Calendar}.
@author Joseph Fialli
@author Kohsuke Kawaguchi
@author Jeff Suttor
@version $Revision: 292853 $, $Date: 2005-09-30 16:42:07 -0400 (Fri, 30 Sep 2005) $
@see XMLGregorianCalendar#add(Duration)
@since 1.5
Immutable representation of a time span as defined in the W3C XML Schema 1.0 specification.
A Duration object represents a period of Gregorian time, which consists of six fields (years, months, days, hours, minutes, and seconds) plus a sign (+/-) field.
The first five fields have non-negative (>=0) integers or null (which represents that the field is not set), and the seconds field has a non-negative decimal or null. A negative sign indicates a negative duration.
This class provides a number of methods that make it easy to use for the duration datatype of XML Schema 1.0 with the errata.
Duration objects only have partial order, where two values A and B maybe either:
For example, 30 days cannot be meaningfully compared to one month. The {@link #compare(Duration duration)} method implements thisrelationship.
See the {@link #isLongerThan(Duration)} method for details aboutthe order relationship among Duration
objects.
This class provides a set of basic arithmetic operations, such as addition, subtraction and multiplication. Because durations don't have total order, an operation could fail for some combinations of operations. For example, you cannot subtract 15 days from 1 month. See the javadoc of those methods for detailed conditions where this could happen.
Also, division of a duration by a number is not provided because the Duration
class can only deal with finite precision decimal numbers. For example, one cannot represent 1 sec divided by 3.
However, you could substitute a division by 3 with multiplying by numbers such as 0.3 or 0.333.
Because some operations of Duration
rely on {@link Calendar}even though {@link Duration} can hold very large or very small values,some of the methods may not work correctly on such Duration
s. The impacted methods document their dependency on {@link Calendar}.
@author Joseph Fialli
@author Kohsuke Kawaguchi
@author Jeff Suttor
@author Sunitha Reddy
@version $Revision: 1.10 $, $Date: 2010-11-01 04:36:08 $
@see XMLGregorianCalendar#add(Duration)
@since 1.5
Duration
is an immutable length of time stored as a number of milliseconds. Various factory and conversion methods are available for convenience. These static factory methods allow easy construction of value objects using either long values like seconds(2034)
or hours(3)
:
Duration.milliseconds(long)
Duration.seconds(int)
Duration.minutes(int)
Duration.hours(int)
Duration.days(int)
...or double-precision floating point values like days(3.2)
:
Duration.milliseconds(double)
Duration.seconds(double)
Duration.minutes(double)
Duration.hours(double)
Duration.days(double)
In the case of milliseconds(double)
, the value will be rounded off to the nearest integral millisecond using Math.round()
.
The precise number of milliseconds represented by a Duration
object can be retrieved by calling the getMilliseconds
method. The value of a Duration
object in a given unit like days or hours can be retrieved by calling one of the following unit methods, each of which returns a double-precision floating point number:
seconds()
minutes()
hours()
days()
Values can be added and subtracted using the add(Duration)
and subtract(Duration)
methods, each of which returns a new immutable Duration
object.
String
values can be converted to Duration
objects using the static valueOf
factory methods. The String
format is the opposite of the one created by toString()
, which converts a Duration
object to a readable form, such as "3.2 hours" or "32.5 minutes". Valid units are: milliseconds, seconds, minutes hours and days. Correct English plural forms are used in creating String
values and are parsed as well. The Locale
is respected and "," will be used instead of "." in the Eurozone.
The benchmark method will "benchmark" a Runnable
or an {@link ICode} implementingobject, returning a Duration
object that represents the amount of time elapsed in running the code.
Finally, the sleep
method will sleep for the value of a Duration
.
@author Jonathan Locke
@since 1.2.6
Implementation of xs:duration.
@author Jochen WiedmannA duration is defined by a fixed number of milliseconds. There is no concept of fields, such as days or seconds, as these fields can vary in length. A duration may be converted to a {@link Period} to obtain field values.This conversion will typically cause a loss of precision however.
Duration is thread-safe and immutable. @author Brian S O'Neill @author Stephen Colebourne @since 1.0
With the constructor {link {@link #Duration(String)} you can create a Duration from a text representation. The syntax is as follows
duration = part [',' part | 'and' part] part = number ['business'] unit number = (0..9)+ unit = (y|year|years|month|months|w|week|weeks|d|day|days|h|hour|hours|min|minute|minutes|s|sec|second|seconds|milli|millis|millisecond|milliseconds)
Duration is immutable.
Syntax: <quantity> [business] <unit>
Where
NumberFormat.getNumberInstance().parse(quantity)
. business
means that only business hours should be taken into account for this duration. With the constructor {link {@link #Duration(String)} you can create a Duration from a text representation. The syntax is as follows
duration = part [',' part | 'and' part] part = number ['business'] unit number = (0..9)+ unit = (y|year|years|month|months|w|week|weeks|d|day|days|h|hour|hours|min|minute|minutes|s|sec|second|seconds|milli|millis|millisecond|milliseconds)
Duration is immutable.
A duration is defined by a fixed number of milliseconds. There is no concept of fields, such as days or seconds, as these fields can vary in length. A duration may be converted to a {@link Period} to obtain field values.This conversion will typically cause a loss of precision however.
Duration is thread-safe and immutable. @author Brian S O'Neill @author Stephen Colebourne @since 1.0
This class models a quantity or amount of time in terms of seconds and nanoseconds. It can be accessed using other duration-based units, such as minutes and hours. In addition, the {@link ChronoUnit#DAYS DAYS} unit can be used and is treated asexactly equal to 24 hours, thus ignoring daylight savings effects. See {@link Period} for the date-based equivalent to this class.
A physical duration could be of infinite length. For practicality, the duration is stored with constraints similar to {@link Instant}. The duration uses nanosecond resolution with a maximum value of the seconds that can be held in a {@code long}. This is greater than the current estimated age of the universe.
The range of a duration requires the storage of a number larger than a {@code long}. To achieve this, the class stores a {@code long} representing seconds and an {@code int}representing nanosecond-of-second, which will always be between 0 and 999,999,999.
The duration is measured in "seconds", but these are not necessarily identical to the scientific "SI second" definition based on atomic clocks. This difference only impacts durations measured near a leap-second and should not affect most applications. See {@link Instant} for a discussion as to the meaning of the second and time-scales.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|