|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectbiweekly.util.Duration
public final class Duration
Represents a period of time (for example, "2 hours and 30 minutes").
This class is immutable. Use the builder() method to construct a new
instance, or the parse(java.lang.String) method to parse a duration string.
Examples:
Duration duration = Duration.builder().hours(2).minutes(30).build();
Duration duration = Duration.parse("PT2H30M");
//add a duration value to a Date
Date start = ...
Date end = duration.add(start);
| Nested Class Summary | |
|---|---|
static class |
Duration.Builder
Builds Duration objects. |
| Method Summary | |
|---|---|
Date |
add(Date date)
Adds this duration value to a Date object. |
static Duration.Builder |
builder()
Creates a builder object for constructing new instances of this class. |
static Duration |
diff(Date start,
Date end)
Builds a duration based on the difference between two dates. |
boolean |
equals(Object obj)
|
static Duration |
fromMillis(long milliseconds)
Builds a duration from a number of milliseconds. |
Integer |
getDays()
Gets the number of days. |
Integer |
getHours()
Gets the number of hours. |
Integer |
getMinutes()
Gets the number of minutes. |
Integer |
getSeconds()
Gets the number of seconds. |
Integer |
getWeeks()
Gets the number of weeks. |
int |
hashCode()
|
boolean |
hasTime()
Determines if any time components are present. |
boolean |
isPrior()
Gets whether the duration is negative. |
static Duration |
parse(String value)
Parses a duration string. |
long |
toMillis()
Converts the duration value to milliseconds. |
String |
toString()
Converts the duration to its string representation. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Method Detail |
|---|
public static Duration parse(String value)
value - the duration string (e.g. "P30DT10H")
IllegalArgumentException - if the duration string is invalid
public static Duration diff(Date start,
Date end)
start - the start dateend - the end date
public static Duration fromMillis(long milliseconds)
milliseconds - the number of milliseconds
public static Duration.Builder builder()
public boolean isPrior()
public Integer getWeeks()
public Integer getDays()
public Integer getHours()
public Integer getMinutes()
public Integer getSeconds()
public Date add(Date date)
Date object.
date - the date to add to
public long toMillis()
isPrior() is true)public boolean hasTime()
public int hashCode()
hashCode in class Objectpublic boolean equals(Object obj)
equals in class Objectpublic String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||