|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.clapper.util.text.Duration
public final class Duration
This class contains methods to parse and format time durations. A time duration is a string like "1 second", "10 minutes", "360 days", "4 hours, 30 seconds". This class can
| Constructor Summary | |
|---|---|
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. |
|
| Method Summary | |
|---|---|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Duration()
Duration(0).
public Duration(long milliseconds)
milliseconds - the elapsed milliseconds
public Duration(java.util.Date date1,
java.util.Date date2)
date1 - the first datedate2 - the second date
public Duration(java.lang.String s,
java.util.Locale locale)
throws java.text.ParseException
s - the string to parselocale - locale to use
java.text.ParseException - bad string
public Duration(java.lang.String s)
throws java.text.ParseException
s - the string to parse
java.text.ParseException - bad string| Method Detail |
|---|
public 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 parse
java.text.ParseException - parse error
public 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
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||