public class TimeSpan extends Object implements Comparable<TimeSpan>, Serializable, Cloneable
Modifier and Type | Field and Description |
---|---|
static int |
DAYS
Constant for days unit and conversion.
|
static int |
HOURS
Constant for hours unit and conversion.
|
static TimeSpan |
MAX_VALUE
Represents the Maximum TimeSpan value.
|
static int |
MILLISECONDS
Constant for milliseconds unit and conversion.
|
static TimeSpan |
MIN_VALUE
Represents the Minimum TimeSpan value.
|
static int |
MINUTES
Constant for minutes unit and conversion.
|
static int |
SECONDS
Constant for seconds unit and conversion.
|
static TimeSpan |
ZERO
Represents the TimeSpan with a value of zero.
|
Constructor and Description |
---|
TimeSpan(int units,
long value)
Creates a new TimeSpan object based on the unit and value entered.
|
TimeSpan(long time)
Creates a new instance of TimeSpan based on the number of milliseconds
entered.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int units,
long value)
Adds a number of units to this TimeSpan.
|
void |
add(TimeSpan timespan)
Adds a TimeSpan to this TimeSpan.
|
Object |
clone()
Returns a clone of this TimeSpan.
|
static int |
compare(TimeSpan first,
TimeSpan second)
Compares two TimeSpan objects.
|
int |
compareTo(TimeSpan o)
Compares this object with the specified object for order.
|
TimeSpan |
duration()
Returns a TimeSpan whose value is the absolute value of this TimeSpan.
|
boolean |
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
long |
getDays()
Gets the number of days (truncated).
|
long |
getHours()
Gets the number of hours (truncated).
|
long |
getMilliseconds()
Gets the number of milliseconds.
|
long |
getMinutes()
Gets the number of minutes (truncated).
|
long |
getSeconds()
Gets the number of seconds (truncated).
|
double |
getTotalDays()
Gets the number of days including fractional days.
|
double |
getTotalHours()
Gets the number of hours including fractional hours.
|
long |
getTotalMilliseconds()
Gets the number of milliseconds.
|
double |
getTotalMinutes()
Gets the number of minutes including fractional minutes.
|
double |
getTotalSeconds()
Gets the number of seconds including fractional seconds.
|
int |
hashCode()
Returns a hash code value for the object.
|
boolean |
isNegative()
Indicates whether the value of the TimeSpan is negative.
|
boolean |
isPositive()
Indicates whether the value of the TimeSpan is positive.
|
boolean |
isZero()
Indicates whether the value of the TimeSpan is zero.
|
TimeSpan |
negate()
Returns a TimeSpan whose value is the negated value of this TimeSpan.
|
static TimeSpan |
parse(String s) |
static TimeSpan |
subtract(Date date1,
Date date2)
Subtracts two Date objects creating a new TimeSpan object.
|
void |
subtract(int units,
long value)
Subtracts a number of units from this TimeSpan.
|
void |
subtract(TimeSpan timespan)
Subtracts a TimeSpan from this TimeSpan.
|
String |
toString()
Returns a string representation of the object in the format.
"[-]d.hh:mm:ss.ff" where "-" is an optional sign for negative TimeSpan
values, the "d" component is days, "hh" is hours, "mm" is minutes, "ss"
is seconds, and "ff" is milliseconds
|
public static final int MILLISECONDS
public static final int SECONDS
public static final int MINUTES
public static final int HOURS
public static final int DAYS
public TimeSpan(long time)
time
- the number of milliseconds for this TimeSpan.public TimeSpan(int units, long value)
units
- the type of unit to use to create a TimeSpan instance.value
- the number of units to use to create a TimeSpan instance.public static TimeSpan subtract(Date date1, Date date2)
date1
- Date to use as the base value.date2
- Date to subtract from the base value.public int compareTo(TimeSpan o)
compareTo
in interface Comparable<TimeSpan>
o
- the Object to be compared.public boolean equals(Object obj)
public int hashCode()
java.util.Hashtable
. The method uses the same algorithm as
found in the Long class.hashCode
in class Object
Object.equals(Object)
,
Hashtable
public String toString()
public boolean isPositive()
public boolean isNegative()
public boolean isZero()
public long getMilliseconds()
public long getTotalMilliseconds()
public long getSeconds()
public double getTotalSeconds()
public long getMinutes()
public double getTotalMinutes()
public long getHours()
public double getTotalHours()
public long getDays()
public double getTotalDays()
public void add(TimeSpan timespan)
timespan
- the TimeSpan to add to this TimeSpan.public void add(int units, long value)
units
- the type of unit to add to this TimeSpan.value
- the number of units to add to this TimeSpan.public static int compare(TimeSpan first, TimeSpan second)
first
- first TimeSpan to use in the compare.second
- second TimeSpan to use in the compare.public TimeSpan duration()
public TimeSpan negate()
public void subtract(TimeSpan timespan)
timespan
- the TimeSpan to subtract from this TimeSpan.public void subtract(int units, long value)
units
- the type of unit to subtract from this TimeSpan.value
- the number of units to subtract from this TimeSpan.Copyright © 2012–2015 Microsoft. All rights reserved.