Class TimeSpan
- java.lang.Object
-
- com.alachisoft.ncache.runtime.util.TimeSpan
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<TimeSpan>
public class TimeSpan extends java.lang.Object implements java.lang.Comparable<TimeSpan>, java.io.Serializable
Represents a time interval.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static longMaxMilliSecondsMaxMilliSeconds.static longMaxSecondsMaxSeconds.static TimeSpanMaxValueMaxValue return TimeSpan.static longMinMilliSecondsMinMilliSeconds.static longMinSecondsMinSeconds.static TimeSpanMinValueMinValue return TimeSpan.static longTicksPerDayTicksPerDay 864,000,000,000.static longTicksPerHourTicksPerHour 36,000,000,000.static longTicksPerMillisecondTicksPerMillisecond.static longTicksPerMinuteTicksPerMinute 600,000,000.static longTicksPerSecondTicksPerSecond 10,000,000.static longTicksPerTenthSecondTicksPerTenthSecond.static TimeSpanZeroZero return TimeSpan.
-
Constructor Summary
Constructors 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TimeSpanAdd(TimeSpan ts)Returns a new TimeSpan object whose value is the sum of the specified TimeSpan object and this instance.static intCompare(TimeSpan t1, TimeSpan t2)intcompareTo(TimeSpan o)intCompareTo(TimeSpan value)Compares this object with the specified object.intCompareTo(java.lang.Object value)Compares this object with the specified object.TimeSpanDuration()Returns a new TimeSpan object whose value is the absolute value of the current TimeSpan object.booleanequals(TimeSpan obj)Returns a value indicating whether this instance is equal to a specified TimeSpan object.static booleanequals(TimeSpan t1, TimeSpan t2)Returns a value that indicates whether two specified instances of TimeSpan are equal.booleanequals(java.lang.Object value)Indicates whether some other object is "equal to" this one.static TimeSpanFromDays(double value)Returns a TimeSpan that represents a specified number of days, where the specification is accurate to the nearest millisecond.static TimeSpanFromHours(double value)Returns a TimeSpan that represents a specified number of hours, where the specification is accurate to the nearest millisecond.static TimeSpanFromMilliseconds(double value)Returns a TimeSpan that represents a specified number of milliseconds.static TimeSpanFromMinutes(double value)Returns a TimeSpan that represents a specified number of minutes, where the specification is accurate to the nearest millisecond.static TimeSpanFromSeconds(double value)Returns a TimeSpan that represents a specified number of seconds, where the specification is accurate to the nearest millisecond.static TimeSpanFromTicks(long value)Returns a TimeSpan that represents a specified time, where the specification is in units of ticks.intgetDays()Gets the days component of the time interval represented by the current TimeSpan class.intgetHours()Gets the hours component of the time interval represented by the current TimeSpan class.intgetMilliseconds()Gets the milliseconds component of the time interval represented by the current TimeSpan class.intgetMinutes()Gets the minutes component of the time interval represented by the current TimeSpan class.intgetSeconds()Gets the seconds component of the time interval represented by the current TimeSpan class.doublegetTotalDays()Gets the value of the current TimeSpan class expressed in whole and fractional days.doublegetTotalHours()Gets the value of the current TimeSpan class expressed in whole and fractional hours.longgetTotalMiliSeconds()Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.doublegetTotalMilliseconds()Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.doublegetTotalMinutes()Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.doublegetTotalSeconds()Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.longgetTotalTicks()Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.inthashCode()Returns a hash code value for the object.TimeSpanNegate()Returns a new TimeSpan object whose value is the negated value of this instance.static TimeSpanOpAddition(TimeSpan t1, TimeSpan t2)Adds two specified TimeSpan instances.static booleanOpEquality(TimeSpan t1, TimeSpan t2)Indicates whether two TimeSpan instances are equal.static booleanOpGreaterThan(TimeSpan t1, TimeSpan t2)Indicates whether a specified TimeSpan is greater than another specified TimeSpan.static booleanOpGreaterThanOrEqual(TimeSpan t1, TimeSpan t2)Indicates whether a specified TimeSpan is greater than or equal to another specified TimeSpan.static booleanOpInequality(TimeSpan t1, TimeSpan t2)Indicates whether two TimeSpan instances are not equal.static booleanOpLessThan(TimeSpan t1, TimeSpan t2)Indicates whether a specified TimeSpan is less than another specified TimeSpan.static booleanOpLessThanOrEqual(TimeSpan t1, TimeSpan t2)Indicates whether a specified TimeSpan is less than or equal to another specified TimeSpan.static TimeSpanOpSubtraction(TimeSpan t1, TimeSpan t2)Subtracts a specified TimeSpan from another specified TimeSpan.static TimeSpanOpUnaryNegation(TimeSpan t)Returns a TimeSpan whose value is the negated value of the specified instance.static TimeSpanOpUnaryPlus(TimeSpan t)Returns the specified instance of TimeSpan.static TimeSpansubtract(java.util.Date from, java.util.Date to)Gets the difference between two dates in the form of a Timespan.TimeSpanSubtract(TimeSpan ts)Returns a new TimeSpan object whose value is the difference between the specified TimeSpan object and this instance.static longTimeToTicks(int hour, int minute, int second)Converts the specified hour, minutes and seconds to equivalent ticks.
-
-
-
Field Detail
-
TicksPerMillisecond
public static final long TicksPerMillisecond
TicksPerMillisecond.- See Also:
- Constant Field Values
-
TicksPerSecond
public static final long TicksPerSecond
TicksPerSecond 10,000,000.- See Also:
- Constant Field Values
-
TicksPerMinute
public static final long TicksPerMinute
TicksPerMinute 600,000,000.- See Also:
- Constant Field Values
-
TicksPerHour
public static final long TicksPerHour
TicksPerHour 36,000,000,000.- See Also:
- Constant Field Values
-
TicksPerDay
public static final long TicksPerDay
TicksPerDay 864,000,000,000.- See Also:
- Constant Field Values
-
MaxSeconds
public static final long MaxSeconds
MaxSeconds.- See Also:
- Constant Field Values
-
MinSeconds
public static final long MinSeconds
MinSeconds.- See Also:
- Constant Field Values
-
MaxMilliSeconds
public static final long MaxMilliSeconds
MaxMilliSeconds.- See Also:
- Constant Field Values
-
MinMilliSeconds
public static final long MinMilliSeconds
MinMilliSeconds.- See Also:
- Constant Field Values
-
TicksPerTenthSecond
public static final long TicksPerTenthSecond
TicksPerTenthSecond.- See Also:
- Constant Field Values
-
Zero
public static final TimeSpan Zero
Zero return TimeSpan.
-
MaxValue
public static final TimeSpan MaxValue
MaxValue return TimeSpan.
-
MinValue
public static final TimeSpan MinValue
MinValue return TimeSpan.
-
-
Constructor Detail
-
TimeSpan
public TimeSpan()
Creates an instance of Timespan.
-
TimeSpan
public TimeSpan(long ticks)
Initializes a new instance of the TimeSpan class to the specified number of ticks.- Parameters:
ticks- A time period expressed in 100-nanosecond units.
-
TimeSpan
public TimeSpan(int hours, int minutes, int seconds)Initializes a new instance of the TimeSpan class to a specified number of hours, minutes, and seconds.- Parameters:
hours- Number of hours.minutes- Number of minutes.seconds- Number of seconds.
-
TimeSpan
public 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.- Parameters:
days- Number of days.hours- Number of hours.minutes- Number of minutes.seconds- Number of seconds.
-
TimeSpan
public 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.- Parameters:
days- Number of days.hours- Number of hours.minutes- Number of minutes.seconds- Number of seconds.milliseconds- Number of milliseconds.
-
-
Method Detail
-
FromDays
public static TimeSpan FromDays(double value)
Returns a TimeSpan that represents a specified number of days, where the specification is accurate to the nearest millisecond.- Parameters:
value- A number of days, accurate to the nearest millisecond.- Returns:
- An object that represents value.
-
equals
public static boolean equals(TimeSpan t1, TimeSpan t2)
Returns a value that indicates whether two specified instances of TimeSpan are equal.- Parameters:
t1- The first time interval to compare.t2- The second time interval to compare.- Returns:
- True, if the values of t1 and t2 are equal; otherwise, false.
-
FromHours
public static TimeSpan FromHours(double value)
Returns a TimeSpan that represents a specified number of hours, where the specification is accurate to the nearest millisecond.- Parameters:
value- A number of hours accurate to the nearest millisecond.- Returns:
- An object that represents value.
-
FromMilliseconds
public static TimeSpan FromMilliseconds(double value)
Returns a TimeSpan that represents a specified number of milliseconds.- Parameters:
value- A number of milliseconds.- Returns:
- An object that represents value.
-
FromMinutes
public static TimeSpan FromMinutes(double value)
Returns a TimeSpan that represents a specified number of minutes, where the specification is accurate to the nearest millisecond.- Parameters:
value- A number of minutes, accurate to the nearest millisecond.- Returns:
- An object that represents value.
-
FromSeconds
public static TimeSpan FromSeconds(double value)
Returns a TimeSpan that represents a specified number of seconds, where the specification is accurate to the nearest millisecond.- Parameters:
value- A number of seconds, accurate to the nearest millisecond.- Returns:
- An object that represents value.
-
FromTicks
public static TimeSpan FromTicks(long value)
Returns a TimeSpan that represents a specified time, where the specification is in units of ticks.- Parameters:
value- A number of ticks that represent a time.- Returns:
- An object that represents value.
-
TimeToTicks
public static long TimeToTicks(int hour, int minute, int second)Converts the specified hour, minutes and seconds to equivalent ticks.- Parameters:
hour- Number of hours.minute- Number of minutes.second- Number of seconds.- Returns:
- The number of ticks equivalent to the specified time.
-
OpUnaryNegation
public static TimeSpan OpUnaryNegation(TimeSpan t)
Returns a TimeSpan whose value is the negated value of the specified instance.- Parameters:
t- The time interval to be negated.- Returns:
- An object that has the same numeric value as this instance, but the opposite sign.
-
OpSubtraction
public static TimeSpan OpSubtraction(TimeSpan t1, TimeSpan t2)
Subtracts a specified TimeSpan from another specified TimeSpan.- Parameters:
t1- The minuend.t2- The subtrahend.- Returns:
- An object whose value is the result of the value of t1 minus the value of t2.
-
OpUnaryPlus
public static TimeSpan OpUnaryPlus(TimeSpan t)
Returns the specified instance of TimeSpan.- Parameters:
t- The time interval to return.- Returns:
- The time interval specified by t.
-
OpAddition
public static TimeSpan OpAddition(TimeSpan t1, TimeSpan t2)
Adds two specified TimeSpan instances.- Parameters:
t1- The first time interval to add.t2- The second time interval to add.- Returns:
- An object whose value is the sum of the values of t1 and t2.
-
OpEquality
public static boolean OpEquality(TimeSpan t1, TimeSpan t2)
Indicates whether two TimeSpan instances are equal.- Parameters:
t1- The first time interval to compare.t2- The second time interval to compare.- Returns:
- True, if the values of t1 and t2 are equal; otherwise, false.
-
OpInequality
public static boolean OpInequality(TimeSpan t1, TimeSpan t2)
Indicates whether two TimeSpan instances are not equal.- Parameters:
t1- The first time interval to compare.t2- The second time interval to compare.- Returns:
- True, if the values of t1 and t2 are not equal; otherwise, false.
-
OpLessThan
public static boolean OpLessThan(TimeSpan t1, TimeSpan t2)
Indicates whether a specified TimeSpan is less than another specified TimeSpan.- Parameters:
t1- The first time interval to compare.t2- The second time interval to compare.- Returns:
- True, if the value of t1 is less than the value of t2; otherwise, false.
-
OpLessThanOrEqual
public static boolean OpLessThanOrEqual(TimeSpan t1, TimeSpan t2)
Indicates whether a specified TimeSpan is less than or equal to another specified TimeSpan.- Parameters:
t1- The first time interval to compare.t2- The second time interval to compare.- Returns:
- True, if the value of t1 is less than or equal to the value of t2; otherwise,false.
-
OpGreaterThan
public static boolean OpGreaterThan(TimeSpan t1, TimeSpan t2)
Indicates whether a specified TimeSpan is greater than another specified TimeSpan.- Parameters:
t1- The first time interval to compare.t2- The second time interval to compare.- Returns:
- True, if the value of t1 is greater than the value of t2; otherwise, false.
-
OpGreaterThanOrEqual
public static boolean OpGreaterThanOrEqual(TimeSpan t1, TimeSpan t2)
Indicates whether a specified TimeSpan is greater than or equal to another specified TimeSpan.- Parameters:
t1- The first time interval to compare.t2- The second time interval to compare.- Returns:
- True, if the value of t1 is greater than or equal to the value of t2; otherwise,false.
-
subtract
public static TimeSpan subtract(java.util.Date from, java.util.Date to) throws java.lang.IllegalArgumentException
Gets the difference between two dates in the form of a Timespan.- Parameters:
from- The first date value to compare.to- The second date value to compare.- Returns:
- The timespan instance indicating the difference between the dates.
- Throws:
java.lang.IllegalArgumentException
-
getDays
public int getDays()
Gets the days component of the time interval represented by the current TimeSpan class.- Returns:
- The day component of this instance. The return value can be positive or negative.
-
getHours
public int getHours()
Gets the hours component of the time interval represented by the current TimeSpan class.- Returns:
- The hour component of the current TimeSpan class. The return value anges from -23 through 23.
-
getMilliseconds
public int getMilliseconds()
Gets the milliseconds component of the time interval represented by the current TimeSpan class.- Returns:
- The millisecond component of the current TimeSpan class. The return value ranges from -999 through 999.
-
getMinutes
public int getMinutes()
Gets the minutes component of the time interval represented by the current TimeSpan class.- Returns:
- The minute component of the current TimeSpan class. The return value ranges from -59 through 59.
-
getSeconds
public int getSeconds()
Gets the seconds component of the time interval represented by the current TimeSpan class.- Returns:
- The second component of the current TimeSpan class. The return value ranges from -59 through 59.
-
getTotalDays
public double getTotalDays()
Gets the value of the current TimeSpan class expressed in whole and fractional days.- Returns:
- The total number of days represented by this instance.
-
getTotalHours
public double getTotalHours()
Gets the value of the current TimeSpan class expressed in whole and fractional hours.- Returns:
- The total number of hours represented by this instance.
-
getTotalMilliseconds
public double getTotalMilliseconds()
Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.- Returns:
- The total number of milliseconds represented by this instance.
-
getTotalMinutes
public double getTotalMinutes()
Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.- Returns:
- The total number of minutes represented by this instance.
-
getTotalSeconds
public double getTotalSeconds()
Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.- Returns:
- The total number of seconds represented by this instance.
-
Add
public TimeSpan Add(TimeSpan ts)
Returns a new TimeSpan object whose value is the sum of the specified TimeSpan object and this instance.- Parameters:
ts- The time interval to add.- Returns:
- A new object that represents the value of this instance plus the value of ts.
-
CompareTo
public int CompareTo(java.lang.Object value)
Compares this object with the specified object. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.- Parameters:
value- The object to be compared with this object.- Returns:
- A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
-
CompareTo
public int CompareTo(TimeSpan value)
Compares this object with the specified object. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.- Parameters:
value- The object to be compared with this object.- Returns:
- A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
-
Duration
public TimeSpan Duration()
Returns a new TimeSpan object whose value is the absolute value of the current TimeSpan object.- Returns:
- A new object whose value is the absolute value of the current TimeSpan object.
-
equals
public boolean equals(java.lang.Object value)
Indicates whether some other object is "equal to" this one.The
equalsmethod implements an equivalence relation on non-null object references:- It is reflexive: for any non-null reference value
x,x.equals(x)should returntrue. - It is symmetric: for any non-null reference values
xandy,x.equals(y)should returntrueif and only ify.equals(x)returnstrue. - It is transitive: for any non-null reference values
x,y, andz, ifx.equals(y)returnstrueandy.equals(z)returnstrue, thenx.equals(z)should returntrue. - It is consistent: for any non-null reference values
xandy, multiple invocations ofx.equals(y)consistently returntrueor consistently returnfalse, provided no information used inequalscomparisons on the objects is modified. - For any non-null reference value
x,x.equals(null)should returnfalse.
The
equalsmethod for classObjectimplements the most discriminating possible equivalence relation on objects; that is, for any non-null reference valuesxandy, this method returnstrueif and only ifxandyrefer to the same object (x == yhas the valuetrue).Note that it is generally necessary to override the
hashCodemethod whenever this method is overridden, so as to maintain the general contract for thehashCodemethod, which states that equal objects must have equal hash codes.- Overrides:
equalsin classjava.lang.Object- Parameters:
value- the reference object with which to compare.- Returns:
trueif this object is the same as the obj argument;falseotherwise.- See Also:
hashCode(),HashMap
- It is reflexive: for any non-null reference value
-
equals
public boolean equals(TimeSpan obj)
Returns a value indicating whether this instance is equal to a specified TimeSpan object.- Parameters:
obj- An object to compare with this instance.- Returns:
- True, if obj represents the same time interval as this instance; otherwise, false.
-
hashCode
public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided byHashMap.The general contract of
hashCodeis:- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
hashCodemethod must consistently return the same integer, provided no information used inequalscomparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equals(Object)method, then calling thehashCodemethod on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal
according to the
Object.equals(java.lang.Object)method, then calling thehashCodemethod 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
Objectdoes 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.)- Overrides:
hashCodein classjava.lang.Object- Returns:
- a hash code value for this object.
- See Also:
Object.equals(java.lang.Object),System.identityHashCode(java.lang.Object)
- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
-
Negate
public TimeSpan Negate()
Returns a new TimeSpan object whose value is the negated value of this instance.- Returns:
- A new object with the same numeric value as this instance, but with the opposite sign.
-
Subtract
public TimeSpan Subtract(TimeSpan ts)
Returns a new TimeSpan object whose value is the difference between the specified TimeSpan object and this instance.- Parameters:
ts- The time interval to be subtracted.- Returns:
- A new time interval whose value is the result of the value of this instance minus the value of ts.
-
compareTo
public int compareTo(TimeSpan o)
- Specified by:
compareToin interfacejava.lang.Comparable<TimeSpan>
-
getTotalTicks
public long getTotalTicks()
Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.- Returns:
- The total number of ticks represented by this instance.
-
getTotalMiliSeconds
public long getTotalMiliSeconds()
Gets the value of the current TimeSpan class expressed in whole and fractional milliseconds.- Returns:
- The total number of ticks represented by this instance.
-
-