public class TimeSpan extends java.lang.Object implements IComparable<TimeSpan>, IEquatable<TimeSpan>
Modifier and Type | Field and Description |
---|---|
static TimeSpan |
MaxValue
Represents the maximum TimeSpan value.
|
static TimeSpan |
MinValue
Represents the minimum TimeSpan value.
|
static long |
TicksPerDay
Represents the number of ticks in 1 day.
|
static long |
TicksPerHour
Represents the number of ticks in 1 hour.
|
static long |
TicksPerMillisecond
Represents the number of ticks in 1 millisecond.
|
static long |
TicksPerMinute
Represents the number of ticks in 1 minute.
|
static long |
TicksPerSecond
Represents the number of ticks in 1 second.
|
static TimeSpan |
Zero
Represents the zero TimeSpan value.
|
Constructor and Description |
---|
TimeSpan(int hours,
int minutes,
int seconds)
Initializes a new TimeSpan to a specified number of hours, minutes, and seconds.
|
TimeSpan(int days,
int hours,
int minutes,
int seconds)
Initializes a new TimeSpan to a specified number of days, hours, minutes, and seconds.
|
TimeSpan(int days,
int hours,
int minutes,
int seconds,
int milliseconds)
Initializes a new TimeSpan to a specified number of days, hours, minutes, seconds, and milliseconds.
|
TimeSpan(long ticks)
Initializes a new TimeSpan to the specified number of ticks.
|
Modifier and Type | Method and Description |
---|---|
TimeSpan |
Add(TimeSpan ts)
Adds the specified TimeSpan to this instance.
|
static int |
Compare(TimeSpan t1,
TimeSpan t2)
Compares two TimeSpan values and returns an integer that indicates their relationship.
|
int |
CompareTo(TimeSpan value)
Compares this instance to a specified TimeSpan object and returns an indication of their relative values.
|
TimeSpan |
Duration()
Returns a new TimeSpan object whose value is the absolute value of the current TimeSpan object.
|
boolean |
equals(java.lang.Object value)
Returns a value indicating whether this instance is equal to a specified 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 indicating whether two specified instances of TimeSpan are equal.
|
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 number of whole days represented by the current TimeSpan structure.
|
int |
getHours()
Gets the number of whole hours represented by the current TimeSpan structure.
|
int |
getMilliseconds()
Gets the number of whole milliseconds represented by the current TimeSpan structure.
|
int |
getMinutes()
Gets the number of whole minutes represented by the current TimeSpan structure.
|
int |
getSeconds()
Gets the number of whole seconds represented by the current TimeSpan structure.
|
long |
getTicks()
Gets the number of ticks that represent the value of the current TimeSpan structure.
|
double |
getTotalDays()
Gets the value of the current TimeSpan structure expressed in whole and fractional days.
|
double |
getTotalHours()
Gets the value of the current TimeSpan structure expressed in whole and fractional hours.
|
double |
getTotalMilliseconds()
Gets the value of the current TimeSpan structure expressed in whole and fractional milliseconds.
|
double |
getTotalMinutes()
Gets the value of the current TimeSpan structure expressed in whole and fractional minutes.
|
double |
getTotalSeconds()
Gets the value of the current TimeSpan structure expressed in whole and fractional seconds.
|
int |
hashCode()
Returns a hash code for this instance.
|
TimeSpan |
Negate()
Returns a TimeSpan whose value is the negated value of this instance.
|
static TimeSpan |
Parse(java.lang.String s)
Constructs a new TimeSpan object from a time interval specified in a string.
|
TimeSpan |
Subtract(TimeSpan ts)
Subtracts the specified TimeSpan from this instance.
|
java.lang.String |
toString()
Returns the string representation of the value of this instance.
|
static boolean |
TryParse(java.lang.String s,
TimeSpan result)
Constructs a new TimeSpan object from a time interval specified in a string.
|
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 TimeSpan Zero
public static final TimeSpan MaxValue
public static final TimeSpan MinValue
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.ArgumentOutOfRangeException
- The parameters specify a TimeSpan value less than MinValue or greater than MaxValue.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.ArgumentOutOfRangeException
- The parameters specify a TimeSpan value less than MinValue or greater than MaxValue.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.ArgumentOutOfRangeException
- The parameters specify a TimeSpan value less than MinValue or greater than MaxValue.public int getDays()
public int getHours()
public int getMilliseconds()
public int getMinutes()
public int getSeconds()
public long getTicks()
public double getTotalDays()
public double getTotalHours()
public double getTotalMilliseconds()
public double getTotalMinutes()
public double getTotalSeconds()
public TimeSpan Add(TimeSpan ts)
ts
- A TimeSpan.OverflowException
- The resulting TimeSpan is less than MinValue or greater than MaxValue.public static int Compare(TimeSpan t1, TimeSpan t2)
t1
- A TimeSpan.t2
- A TimeSpan.public int CompareTo(TimeSpan value)
CompareTo
in interface IComparable<TimeSpan>
value
- A TimeSpan object to compare to this instance.public TimeSpan Duration()
OverflowException
- The value of this instance is MinValue.public boolean equals(java.lang.Object value)
equals
in class java.lang.Object
value
- An object to compare with this instance.public boolean Equals(TimeSpan obj)
Equals
in interface IEquatable<TimeSpan>
obj
- An TimeSpan object to compare with this instance.public static boolean Equals(TimeSpan t1, TimeSpan t2)
t1
- A TimeSpan.t2
- A TimeSpan.public static TimeSpan FromDays(double value)
value
- A number of days, accurate to the nearest millisecond.ArgumentException
- value is equal to NaN.OverflowException
- value is less than MinValue or greater than MaxValue.public static TimeSpan FromHours(double value)
value
- A number of hours accurate to the nearest millisecond.ArgumentException
- value is equal to NaN.OverflowException
- value is less than MinValue or greater than MaxValue.public static TimeSpan FromMilliseconds(double value)
value
- A number of milliseconds.ArgumentException
- value is equal to NaN.OverflowException
- value is less than MinValue or greater than MaxValue.public static TimeSpan FromMinutes(double value)
value
- A number of minutes, accurate to the nearest millisecond.ArgumentException
- value is equal to NaN.OverflowException
- value is less than MinValue or greater than MaxValue.public static TimeSpan FromSeconds(double value)
value
- A number of seconds, accurate to the nearest millisecond.ArgumentException
- value is equal to NaN.OverflowException
- value is less than MinValue or greater than MaxValue.public static TimeSpan FromTicks(long value)
value
- A number of ticks that represent a time.public int hashCode()
hashCode
in class java.lang.Object
public TimeSpan Negate()
OverflowException
- The negated value of this instance cannot be represented by a TimeSpan; that is, the value of this instance is MinValue.public static TimeSpan Parse(java.lang.String s)
s
- A string that specifies a time interval.FormatException
- s has an invalid format.ArgumentNullException
- s is null.OverflowException
- s represents a number less than MinValue or greater than MaxValue.-or- At least one of the days, hours, minutes, or seconds components is outside its valid range.public TimeSpan Subtract(TimeSpan ts)
ts
- A TimeSpan.OverflowException
- The return value is less than MinValue or greater than MaxValue.public java.lang.String toString()
toString
in class java.lang.Object
public static boolean TryParse(java.lang.String s, TimeSpan result)
s
- A string that specifies a time interval.result
- When this method returns, contains an object that represents the time interval specified by s, or Zero if the conversion failed. This parameter is passed uninitialized.