public final class Duration
extends java.lang.Object
Constructor and Description |
---|
Duration()
Default constructor.
|
Duration(java.util.Date date1,
java.util.Date date2)
Create a new Duration object by determining the amount
of time between two dates.
|
Duration(long milliseconds)
Create a new Duration object from a long integer representing
some elapsed number of milliseconds.
|
Duration(java.lang.String s)
Create a new Duration object by parsing the specified
duration string.
|
Duration(java.lang.String s,
java.util.Locale locale)
Create a new Duration object by parsing the specified
duration string.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
format()
Format the duration value as a string, like the kind of string
handled by the
parse(java.lang.String) method. |
java.lang.String |
format(java.util.Locale locale)
Format the duration value as a string, like the kind of string
handled by the
parse(java.lang.String) method. |
long |
getDuration()
Get the stored duration value, in milliseconds.
|
void |
parse(java.lang.String s)
Parse a string containing a textual description of a duration,
setting this object's value to the result of the parse.
|
void |
parse(java.lang.String s,
java.util.Locale locale)
Parse a string containing a textual description of a duration,
setting this object's value to the result of the parse.
|
java.lang.String |
toString()
Return a string representation of this duration.
|
public Duration()
public Duration(long milliseconds)
milliseconds
- the elapsed millisecondspublic Duration(java.util.Date date1, java.util.Date date2)
date1
- the first datedate2
- the second datepublic Duration(java.lang.String s, java.util.Locale locale) throws java.text.ParseException
s
- the string to parselocale
- locale to usejava.text.ParseException
- bad stringpublic Duration(java.lang.String s) throws java.text.ParseException
s
- the string to parsejava.text.ParseException
- bad stringpublic long getDuration()
public java.lang.String format()
parse(java.lang.String)
method. This version formats the string
using the default locale. For a complete description of what this
method produces, see format(Locale)
.public java.lang.String format(java.util.Locale locale)
Format the duration value as a string, like the kind of string
handled by the parse(java.lang.String)
method. For instance, a duration value
of 1 is formatted as "1 millisecond". A duration value of 86460000
is formatted as "1 day, 1 hour".
locale
- Locale to use for the strings, or null for the default.
If there's no bundle for the specified locale, English
is used.public void parse(java.lang.String s) throws java.text.ParseException
parse()
that takes a Locale
parameter for a more complete explanation of the supported tokens.s
- the string to parsejava.text.ParseException
- parse errorpublic void parse(java.lang.String s, java.util.Locale locale) throws java.text.ParseException
s
- the string to parselocale
- the locale to use when interpreting the tokens, or null
for the default.java.text.ParseException
- parse errorpublic java.lang.String toString()
format()
method. format()
produces a natural language phrase, whereas toString() just
returns the equivalent of
String.valueOf(Duration.getDuration()).toString
in class java.lang.Object