TimeDelta

Inheritance: java.lang.Object

public class TimeDelta

Represents a difference between two timestamps.

Constructors

ConstructorDescription
TimeDelta(int hours, int minutes, int seconds)Initializes new instance of TimeDelta to the specified number of hours, minutes and seconds.
TimeDelta(int days, int hours, int minutes, int seconds, int milliseconds)Initializes new instance of TimeDelta to the specified number of days, hours, minutes, seconds and milliseconds.

Methods

MethodDescription
add(TimeDelta other)Returns a new TimeDelta object whose value is a sum of this and other instance.
clone(){@inheritDoc}
compare(TimeDelta t1, TimeDelta t2)Compares two TimeDelta values and returns an integer that indicates whether the first value is shorter than, equal to, or longer than the second value.
compareTo(TimeDelta other)Compares this instance to a specified TimeDelta object and returns an integer that indicates whether this instance is shorter than, equal to, or longer than the TimeSpan object.
equals(TimeDelta other)Indicates whether some other time span is equal to this one.
equals(TimeDelta t1, TimeDelta t2)Checks two instances for equality.
equals(Object other){@inheritDoc}
fromDays(double value)Returns a TimeDelta that represents a specified number of days (rounded to the nearest millisecond).
fromHours(double value)Returns a TimeDelta that represents a specified number of hours (rounded to the nearest millisecond).
fromMilliseconds(double value)Returns a TimeDelta that represents a specified number of milliseconds (rounded to the nearest millisecond).
fromMinutes(double value)Returns a TimeDelta that represents a specified number of minutes (rounded to the nearest millisecond).
fromSeconds(double value)Returns a TimeDelta that represents a specified number of seconds (rounded to the nearest millisecond).
getDays()Returns the days component of the time interval, represented by this instance.
getHours()Returns the hours component of the time interval, represented by this instance.
getMilliseconds()Returns the milliseconds component of the time interval, represented by this instance.
getMinutes()Returns the minutes component of the time interval, represented by this instance.
getSeconds()Returns the seconds component of the time interval, represented by this instance.
getTotalDays()Returns the value of the current instance expressed in whole and fractional days.
getTotalHours()Returns the value of the current instance expressed in whole and fractional hours.
getTotalMilliseconds()Returns the value of the current instance expressed in whole and fractional milliseconds.
getTotalMinutes()Returns the value of the current instance expressed in whole and fractional minutes.
getTotalSeconds()Returns the value of the current instance expressed in whole and fractional seconds.
hashCode(){@inheritDoc}
negate()Returns a new TimeDelta whose value is the negated value of this instance.
parse(String s)Converts the string representation of a time interval to its TimeDelta equivalent.
subtract(TimeDelta other)Returns a new TimeDelta object whose value is a difference between this and other instances.
toString(){@inheritDoc}
tryParse(String s, TimeDelta[] result)Converts the string representation of a time interval to its TimeDelta equivalent and returns a value that indicates whether the conversion succeeded.

TimeDelta(int hours, int minutes, int seconds)

public TimeDelta(int hours, int minutes, int seconds)

Initializes new instance of TimeDelta to the specified number of hours, minutes and seconds.

Parameters:

ParameterTypeDescription
hoursintnumber of hours.
minutesintnumber of minutes.
secondsintnumber of seconds.

TimeDelta(int days, int hours, int minutes, int seconds, int milliseconds)

public TimeDelta(int days, int hours, int minutes, int seconds, int milliseconds)

Initializes new instance of TimeDelta to the specified number of days, hours, minutes, seconds and milliseconds.

Parameters:

ParameterTypeDescription
daysintnumber of days.
hoursintnumber of hours.
minutesintnumber of minutes.
secondsintnumber of seconds.
millisecondsintnumber of milliseconds.

add(TimeDelta other)

public TimeDelta add(TimeDelta other)

Returns a new TimeDelta object whose value is a sum of this and other instance.

Parameters:

ParameterTypeDescription
otherTimeDeltathe instance to sum with.

Returns: TimeDelta - a new object that represents the value of this instance plus value of other instance.

clone()

public Object clone()

Returns: java.lang.Object - {@inheritDoc}

compare(TimeDelta t1, TimeDelta t2)

public static int compare(TimeDelta t1, TimeDelta t2)

Compares two TimeDelta values and returns an integer that indicates whether the first value is shorter than, equal to, or longer than the second value.

Parameters:

ParameterTypeDescription
t1TimeDeltathe first time interval to compare.
t2TimeDeltathe second time interval to compare.

Returns: int - -1 if t1 is shorter than t2, 0 if t1 equals to t2 and 1 if t1 is longer than t2.

compareTo(TimeDelta other)

public int compareTo(TimeDelta other)

Compares this instance to a specified TimeDelta object and returns an integer that indicates whether this instance is shorter than, equal to, or longer than the TimeSpan object.

Parameters:

ParameterTypeDescription
otherTimeDeltaan instance to compare with.

Returns: int - -1 if this instance is shorter than other, 0 if this instance equals to other and 1 if this instance is longer than other.

equals(TimeDelta other)

public boolean equals(TimeDelta other)

Indicates whether some other time span is equal to this one.

Parameters:

ParameterTypeDescription
otherTimeDeltatime span to compare with.

Returns: boolean - true if intervals equal; false otherwise.

equals(TimeDelta t1, TimeDelta t2)

public static boolean equals(TimeDelta t1, TimeDelta t2)

Checks two instances for equality.

Parameters:

ParameterTypeDescription
t1TimeDeltafirst instance.
t2TimeDeltasecond instance.

Returns: boolean - true if instances are equal; false otherwise.

equals(Object other)

public boolean equals(Object other)

Parameters:

ParameterTypeDescription
otherjava.lang.Object{@inheritDoc}

Returns: boolean - {@inheritDoc}

fromDays(double value)

public static TimeDelta fromDays(double value)

Returns a TimeDelta that represents a specified number of days (rounded to the nearest millisecond).

Parameters:

ParameterTypeDescription
valuedoublea number of days.

Returns: TimeDelta - an object that represents value.

fromHours(double value)

public static TimeDelta fromHours(double value)

Returns a TimeDelta that represents a specified number of hours (rounded to the nearest millisecond).

Parameters:

ParameterTypeDescription
valuedoublea number of hours.

Returns: TimeDelta - an object that represents value.

fromMilliseconds(double value)

public static TimeDelta fromMilliseconds(double value)

Returns a TimeDelta that represents a specified number of milliseconds (rounded to the nearest millisecond).

Parameters:

ParameterTypeDescription
valuedoublea number of milliseconds.

Returns: TimeDelta - an object that represents value.

fromMinutes(double value)

public static TimeDelta fromMinutes(double value)

Returns a TimeDelta that represents a specified number of minutes (rounded to the nearest millisecond).

Parameters:

ParameterTypeDescription
valuedoublea number of minutes.

Returns: TimeDelta - an object that represents value.

fromSeconds(double value)

public static TimeDelta fromSeconds(double value)

Returns a TimeDelta that represents a specified number of seconds (rounded to the nearest millisecond).

Parameters:

ParameterTypeDescription
valuedoublea number of seconds.

Returns: TimeDelta - an object that represents value.

getDays()

public int getDays()

Returns the days component of the time interval, represented by this instance.

Returns: int - the days component of the time inteval. Can be positive or negative.

getHours()

public int getHours()

Returns the hours component of the time interval, represented by this instance.

Returns: int - the hours component of the time interval in range from -23 through 23.

getMilliseconds()

public int getMilliseconds()

Returns the milliseconds component of the time interval, represented by this instance.

Returns: int - the milliseconds component of the time interval in range from -999 through 999.

getMinutes()

public int getMinutes()

Returns the minutes component of the time interval, represented by this instance.

Returns: int - the minutes component of the time interval in range from -59 through 59.

getSeconds()

public int getSeconds()

Returns the seconds component of the time interval, represented by this instance.

Returns: int - the seconds component of the time interval in range from -59 through 59.

getTotalDays()

public double getTotalDays()

Returns the value of the current instance expressed in whole and fractional days.

Returns: double - the total number of days represented by this instance.

getTotalHours()

public double getTotalHours()

Returns the value of the current instance expressed in whole and fractional hours.

Returns: double - the total number of hours represented by this instance.

getTotalMilliseconds()

public double getTotalMilliseconds()

Returns the value of the current instance expressed in whole and fractional milliseconds.

Returns: double - the total number of milliseconds represented by this instance.

getTotalMinutes()

public double getTotalMinutes()

Returns the value of the current instance expressed in whole and fractional minutes.

Returns: double - the total number of minutes represented by this instance.

getTotalSeconds()

public double getTotalSeconds()

Returns the value of the current instance expressed in whole and fractional seconds.

Returns: double - the total number of seconds represented by this instance.

hashCode()

public int hashCode()

Returns: int - {@inheritDoc}

negate()

public TimeDelta negate()

Returns a new TimeDelta whose value is the negated value of this instance.

Returns: TimeDelta - A new object with the same numeric value as this instance, but with the opposite sign.

parse(String s)

public static TimeDelta parse(String s)

Converts the string representation of a time interval to its TimeDelta equivalent.

Parameters:

ParameterTypeDescription
sjava.lang.Stringa string that specifies the time interval to convert.

Returns: TimeDelta - a time interval that corresponds to s.

subtract(TimeDelta other)

public TimeDelta subtract(TimeDelta other)

Returns a new TimeDelta object whose value is a difference between this and other instances.

Parameters:

ParameterTypeDescription
otherTimeDeltathe instance to subtract.

Returns: TimeDelta - a new object that represents the value of this instance minus value of other instance.

toString()

public String toString()

Returns: java.lang.String - {@inheritDoc}

tryParse(String s, TimeDelta[] result)

public static boolean tryParse(String s, TimeDelta[] result)

Converts the string representation of a time interval to its TimeDelta equivalent and returns a value that indicates whether the conversion succeeded.

Parameters:

ParameterTypeDescription
sjava.lang.Stringa string that specifies the time interval to convert.
resultTimeDelta[]this array must have at least one element. When this method returns, result[0] contains an object that represents the time interval specified by s, or a zero-length time interval if the conversion failed.

Returns: boolean - true if s was converted successfully; otherwise, false.