java.io.Serializable
, java.lang.Comparable<TimeSpan>
public class TimeSpan extends java.lang.Object implements java.lang.Comparable<TimeSpan>, java.io.Serializable
Modifier and Type | Field | Description |
---|---|---|
static long |
MaxMilliSeconds |
MaxMilliSeconds
|
static long |
MaxSeconds |
MaxSeconds
|
static TimeSpan |
MaxValue |
MaxValue return TimeSpan
|
static long |
MinMilliSeconds |
MinMilliSeconds
|
static long |
MinSeconds |
MinSeconds
|
static TimeSpan |
MinValue |
MinValue return TimeSpan
|
static long |
TicksPerDay |
TicksPerDay 864,000,000,000
|
static long |
TicksPerHour |
TicksPerHour 36,000,000,000
|
static long |
TicksPerMillisecond |
TicksPerMillisecond
|
static long |
TicksPerMinute |
TicksPerMinute 600,000,000
|
static long |
TicksPerSecond |
TicksPerSecond 10,000,000
|
static long |
TicksPerTenthSecond |
TicksPerTenthSecond
|
static TimeSpan |
Zero |
Zero return TimeSpan
|
Constructor | Description |
---|---|
TimeSpan() |
Creates an instance of Timespan.
|
TimeSpan(int hours,
int minutes,
int seconds) |
Initializes a new instance of the TimeSpan class to a specified number of hours, minutes, and seconds.
|
TimeSpan(int days,
int hours,
int minutes,
int seconds) |
Initializes a new instance of the TimeSpan class to a specified number
of days, hours, minutes, and seconds.
|
TimeSpan(int days,
int hours,
int minutes,
int seconds,
int milliseconds) |
Initializes a new instance of the TimeSpan class to a specified number
of days, hours, minutes, seconds, and milliseconds.
|
TimeSpan(long ticks) |
Initializes a new instance of the TimeSpan class to the specified number of ticks.
|
Modifier and Type | Method | Description |
---|---|---|
TimeSpan |
Add(TimeSpan ts) |
Returns a new TimeSpan object whose value is the sum of the specified
TimeSpan object and this instance.
|
static int |
Compare(TimeSpan t1,
TimeSpan t2) |
|
int |
compareTo(TimeSpan o) |
|
int |
CompareTo(TimeSpan value) |
Compares this object with the specified object.
|
int |
CompareTo(java.lang.Object value) |
Compares this object with the specified object.
|
TimeSpan |
Duration() |
Returns a new TimeSpan object whose value is the absolute value of the current TimeSpan object.
|
boolean |
equals(TimeSpan obj) |
Returns a value indicating whether this instance is equal to a specified TimeSpan object.
|
static boolean |
equals(TimeSpan t1,
TimeSpan t2) |
Returns a value that indicates whether two specified instances of TimeSpan are equal.
|
boolean |
equals(java.lang.Object value) |
Indicates whether some other object is "equal to" this one.
|
static TimeSpan |
FromDays(double value) |
Returns a TimeSpan that represents a specified number of days, where the
specification is accurate to the nearest millisecond.
|
static TimeSpan |
FromHours(double value) |
Returns a TimeSpan that represents a specified number of hours, where
the specification is accurate to the nearest millisecond.
|
static TimeSpan |
FromMilliseconds(double value) |
Returns a TimeSpan that represents a specified number of milliseconds.
|
static TimeSpan |
FromMinutes(double value) |
Returns a TimeSpan that represents a specified number of minutes, where
the specification is accurate to the nearest millisecond.
|
static TimeSpan |
FromSeconds(double value) |
Returns a TimeSpan that represents a specified number of seconds, where
the specification is accurate to the nearest millisecond.
|
static TimeSpan |
FromTicks(long value) |
Returns a TimeSpan that represents a specified time, where the specification
is in units of ticks.
|
int |
getDays() |
Gets the days component of the time interval represented by the current TimeSpan class.
|
int |
getHours() |
Gets the hours component of the time interval represented by the current TimeSpan class.
|
int |
getMilliseconds() |
Gets the milliseconds component of the time interval represented by the current TimeSpan class.
|
int |
getMinutes() |
Gets the minutes component of the time interval represented by the current TimeSpan class.
|
int |
getSeconds() |
Gets the seconds component of the time interval represented by the current TimeSpan class.
|
double |
getTotalDays() |
Gets the value of the current TimeSpan class expressed in whole and fractional days.
|
double |
getTotalHours() |
Gets the value of the current TimeSpan class expressed in whole and fractional hours.
|
double |
getTotalMilliseconds() |
Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.
|
double |
getTotalMinutes() |
Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.
|
double |
getTotalSeconds() |
Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.
|
long |
getTotalTicks() |
Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.
|
int |
hashCode() |
Returns a hash code value for the object.
|
TimeSpan |
Negate() |
Returns a new TimeSpan object whose value is the negated value of this instance.
|
static TimeSpan |
OpAddition(TimeSpan t1,
TimeSpan t2) |
Adds two specified TimeSpan instances.
|
static boolean |
OpEquality(TimeSpan t1,
TimeSpan t2) |
Indicates whether two TimeSpan instances are equal.
|
static boolean |
OpGreaterThan(TimeSpan t1,
TimeSpan t2) |
Indicates whether a specified TimeSpan is greater than another specified TimeSpan.
|
static boolean |
OpGreaterThanOrEqual(TimeSpan t1,
TimeSpan t2) |
Indicates whether a specified TimeSpan is greater than or equal to another specified TimeSpan.
|
static boolean |
OpInequality(TimeSpan t1,
TimeSpan t2) |
Indicates whether two TimeSpan instances are not equal.
|
static boolean |
OpLessThan(TimeSpan t1,
TimeSpan t2) |
Indicates whether a specified TimeSpan is less than another specified TimeSpan.
|
static boolean |
OpLessThanOrEqual(TimeSpan t1,
TimeSpan t2) |
Indicates whether a specified TimeSpan is less than or equal to another specified TimeSpan.
|
static TimeSpan |
OpSubtraction(TimeSpan t1,
TimeSpan t2) |
Subtracts a specified TimeSpan from another specified TimeSpan.
|
static TimeSpan |
OpUnaryNegation(TimeSpan t) |
Returns a TimeSpan whose value is the negated value of the specified instance.
|
static TimeSpan |
OpUnaryPlus(TimeSpan t) |
Returns the specified instance of TimeSpan.
|
static TimeSpan |
subtract(java.util.Date from,
java.util.Date to) |
Gets the difference between two dates in the form of a Timespan.
|
TimeSpan |
Subtract(TimeSpan ts) |
Returns a new TimeSpan object whose value is the difference between the
specified TimeSpan object and this instance.
|
static long |
TimeToTicks(int hour,
int minute,
int second) |
Converts the specified hour,minutes and seconds to equivalent ticks.
|
public static final long TicksPerMillisecond
public static final long TicksPerSecond
public static final long TicksPerMinute
public static final long TicksPerHour
public static final long TicksPerDay
public static final long MaxSeconds
public static final long MinSeconds
public static final long MaxMilliSeconds
public static final long MinMilliSeconds
public static final long TicksPerTenthSecond
public static final TimeSpan Zero
public static final TimeSpan MaxValue
public static final TimeSpan MinValue
public TimeSpan()
public TimeSpan(long ticks)
ticks
- A time period expressed in 100-nanosecond units.public TimeSpan(int hours, int minutes, int seconds)
hours
- Number of hours.minutes
- Number of minutes.seconds
- Number of seconds.public TimeSpan(int days, int hours, int minutes, int seconds)
days
- Number of days.hours
- Number of hours.minutes
- Number of minutes.seconds
- Number of seconds.public TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds)
days
- Number of days.hours
- Number of hours.minutes
- Number of minutes.seconds
- Number of seconds.milliseconds
- Number of milliseconds.public static TimeSpan FromDays(double value)
value
- A number of days, accurate to the nearest millisecond.public static boolean equals(TimeSpan t1, TimeSpan t2)
t1
- The first time interval to compare.t2
- The second time interval to compare.public static TimeSpan FromHours(double value)
value
- A number of hours accurate to the nearest millisecond.public static TimeSpan FromMilliseconds(double value)
value
- A number of milliseconds.public static TimeSpan FromMinutes(double value)
value
- A number of minutes, accurate to the nearest millisecond.public static TimeSpan FromSeconds(double value)
value
- A number of seconds, accurate to the nearest millisecond.public static TimeSpan FromTicks(long value)
value
- A number of ticks that represent a time.public static long TimeToTicks(int hour, int minute, int second)
hour
- Number of hours.minute
- Number of minutes.second
- Number of seconds.public static TimeSpan OpUnaryNegation(TimeSpan t)
t
- The time interval to be negated.public static TimeSpan OpSubtraction(TimeSpan t1, TimeSpan t2)
t1
- The minuend.t2
- The subtrahend.public static TimeSpan OpUnaryPlus(TimeSpan t)
t
- The time interval to return.public static TimeSpan OpAddition(TimeSpan t1, TimeSpan t2)
t1
- The first time interval to add.t2
- The second time interval to add.public static boolean OpEquality(TimeSpan t1, TimeSpan t2)
t1
- The first time interval to compare.t2
- The second time interval to compare.public static boolean OpInequality(TimeSpan t1, TimeSpan t2)
t1
- The first time interval to compare.t2
- The second time interval to compare.public static boolean OpLessThan(TimeSpan t1, TimeSpan t2)
t1
- The first time interval to compare.t2
- The second time interval to compare.public static boolean OpLessThanOrEqual(TimeSpan t1, TimeSpan t2)
t1
- The first time interval to compare.t2
- The second time interval to compare.public static boolean OpGreaterThan(TimeSpan t1, TimeSpan t2)
t1
- The first time interval to compare.t2
- The second time interval to compare.public static boolean OpGreaterThanOrEqual(TimeSpan t1, TimeSpan t2)
t1
- The first time interval to compare.t2
- The second time interval to compare.public static TimeSpan subtract(java.util.Date from, java.util.Date to) throws java.lang.IllegalArgumentException
from
- The first date value to compare.to
- The second date value to compare.java.lang.IllegalArgumentException
public int getDays()
public int getHours()
public int getMilliseconds()
public int getMinutes()
public int getSeconds()
public double getTotalDays()
public double getTotalHours()
public double getTotalMilliseconds()
public double getTotalMinutes()
public double getTotalSeconds()
public TimeSpan Add(TimeSpan ts)
ts
- The time interval to add.public int CompareTo(java.lang.Object value)
value
- The object to be compared with this object.public int CompareTo(TimeSpan value)
value
- The object to be compared with this object.public TimeSpan Duration()
public boolean equals(java.lang.Object value)
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
x
and y
, multiple invocations of
x.equals(y)
consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
x
,
x.equals(null)
should return false
.
The equals
method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode
method, which states
that equal objects must have equal hash codes.
equals
in class java.lang.Object
value
- the reference object with which to compare.true
if this object is the same as the obj
argument; false
otherwise.hashCode()
,
HashMap
public boolean equals(TimeSpan obj)
obj
- An object to compare with this instance.public int hashCode()
HashMap
.
The general contract of hashCode
is:
hashCode
method
must consistently return the same integer, provided no information
used in equals
comparisons on the object is modified.
This integer need not remain consistent from one execution of an
application to another execution of the same application.
equals(Object)
method, then calling the hashCode
method on each of
the two objects must produce the same integer result.
Object.equals(java.lang.Object)
method, then calling the hashCode
method on each of the
two objects must produce distinct integer results. However, the
programmer should be aware that producing distinct integer results
for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined
by class Object
does return distinct integers for
distinct objects. (The hashCode may or may not be implemented
as some function of an object's memory address at some point
in time.)
hashCode
in class java.lang.Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public TimeSpan Negate()
public TimeSpan Subtract(TimeSpan ts)
ts
- The time interval to be subtracted.public int compareTo(TimeSpan o)
compareTo
in interface java.lang.Comparable<TimeSpan>
public long getTotalTicks()