Codecore Logo
Quick Search
»
Advanced Search »

TimeSpan Object

RSS
Represents a time interval.


Constructors

TimeSpan( )

Initializes a new DateTime instance to the current date and time.

Syntax:

TimeSpan( )

Parameters:

none

Example:


ts = new TimeSpan();

TimeSpan( Number, Number, Number )

Initializes a new TimeSpan to a specified number of hours, minutes, and seconds.

Syntax:

TimeSpan( Number hours, Number minutes, Number seconds )

Parameters:

hours: Number of hours.
minutes: Number of minutes.
seconds: Number of seconds.

Example:


ts = new TimeSpan(12, 30, 0);

TimeSpan( Number, Number, Number, Number )

Initializes a new TimeSpan to a specified number of days, hours, minutes, and seconds.

Syntax:

TimeSpan( Number days, Number hours, Number minutes, Number seconds )

Parameters:

days: Number of days.
hours: Number of hours.
minutes: Number of minutes.
seconds: Number of seconds.

Example:


ts = new TimeSpan(1, 12, 30, 0);

TimeSpan( Number, Number, Number, Number, Number )

Initializes a new TimeSpan to a specified number of days, hours, minutes, and seconds.

Syntax:

TimeSpan( Number days, Number hours, Number minutes, Number seconds, Number milliseconds )

Parameters:

days: Number of days.
hours: Number of hours.
minutes: Number of minutes.
seconds: Number of seconds.
milliseconds: Number of milliseconds.

Example:


ts = new TimeSpan(1, 12, 30, 0, 0);

Instance Properties

Days

Gets the number of whole days represented by the current TimeSpan.

Accessibility : Read Only

Type: Number

Example:


ts = new TimeSpan(10, 5, 1, 30, 100);
days = ts.Days; // results in 10.

Hours

Gets the number of whole hours represented by the current TimeSpan.

Accessibility : Read Only

Type: Number

Example:


ts = new TimeSpan(10, 5, 1, 30, 100);
hours = ts.Hours; // results in 5.

Minutes

Gets the number of whole minutes represented by the current TimeSpan.

Accessibility : Read Only

Type: Number

Example:


ts = new TimeSpan(10, 5, 1, 30, 100);
minutes = ts.Minutes; // results in 1.

Seconds

Gets the number of whole seconds represented by the current TimeSpan.

Accessibility : Read Only

Type: Number

Example:


ts = new TimeSpan(10, 5, 1, 30, 100);
seconds = ts.Seconds; // results in 30.

Milliseconds

Gets the number of whole milliseconds represented by the current TimeSpan.

Accessibility : Read Only

Type: Number

Example:


ts = new TimeSpan(10, 5, 1, 30, 100);
milliseconds = ts.Milliseconds; // results in 100.

TotalDays

Gets the value of the TimeSpan expressed in whole and fractional days.

Accessibility : Read Only

Type: Number

Example:


ts = new TimeSpan(10, 5, 1, 30, 100);
days = ts.TotalDays; // results in 10.209376157407407

TotalHours

Gets the value of the TimeSpan expressed in whole and fractional hours.

Accessibility : Read Only

Type: Number

Example:


ts = new TimeSpan(10, 5, 1, 30, 100);
hours = ts.TotalHours; // results in 245.02502777777778

TotalMinutes

Gets the value of the TimeSpan expressed in whole and fractional minutes.

Accessibility : Read Only

Type: Number

Example:


ts = new TimeSpan(10, 5, 1, 30, 100);
minutes = ts.TotalMinutes; // results in 14701.501666666667

TotalSeconds

Gets the value of the TimeSpan expressed in whole and fractional seconds.

Accessibility : Read Only

Type: Number

Example:


ts = new TimeSpan(10, 5, 1, 30, 100);
seconds = ts.TotalSeconds; // results in 882090.1

TotalMilliseconds

Gets the value of the TimeSpan expressed in whole and fractional milliseconds.

Accessibility : Read Only

Type: Number

Example:


ts = new TimeSpan(10, 5, 1, 30, 100);
milliseconds = ts.TotalMilliseconds; // results in 882090100.0

Instance Methods

Add ( TimeSpan )

Adds the specified TimeSpan to this instance.

Syntax:

TimeSpan Add( TimeSpan timeSpan )

Parameters:

timeSpan: The time interval to add.

Return Value

An object that represents the value of this instance plus the value of timeSpan.

Example:


ts1 = new TimeSpan(5,0,0);
ts2 = new TimeSpan(2,0,0);
ts = ts1.Add(ts2); // results in a TimeSpan of 7 days.

Duration

Returns a new TimeSpan whose value is the absolute value of this instance.

Syntax:

TimeSpan Duration( )

Parameters:

none

Return Value

A new object whose value is the absolute value of the current TimeSpan object.

Example:


ts1 = new TimeSpan(-5,0,0);
ts2 = ts1.Duration(); // results in a TimeSpan of 5 days.

Negate

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

Syntax:

TimeSpan Negate( )

Parameters:

none

Return Value

The same numeric value as this instance, but with the opposite sign.

Example:


ts1 = new TimeSpan(5,0,0);
ts2 = ts1.Negate(); // results in a TimeSpan of -5 days.

Subtract ( TimeSpan )

Subtracts the specified TimeSpan from this instance.

Syntax:

TimeSpan Subtract( TimeSpan timeSpan )

Parameters:

timeSpan: The time interval to be subtracted.

Return Value

A time interval whose value is the result of the value of this instance minus the value of timeSpan.

Example:


ts1 = new TimeSpan(5,0,0);
ts2 = new TimeSpan(2,0,0);
ts = ts1.Subtract(ts2); // results in a TimeSpan of 3 days.

ToString

Converts the value of this instance to its equivalent string representation using the computers current format.

Syntax:

String ToString( )

Parameters:

none

Return Value

The string representation of the current TimeSpan value.

Example:


ts = new TimeSpan(5,0,0);
s = ts.ToString(); // results in "05:00:00".

Static Methods

FromHours( Number )

Returns a TimeSpan that represents a specified number of hours where the specification is accurate to the nearest millisecond.

Syntax:

TimeSpan FromHours( Number hours)

Parameters:

hours: A number of hours, accurate to the nearest millisecond.

Return Value

An object that represents hours.

Example:


ts = TimeSpan.FromHours(5.5); // results in a TimeSpan of 5 hours and 30 minutes.

FromMinutes( Number )

Returns a TimeSpan that represents a specified number of minutes where the specification is accurate to the nearest millisecond.

Syntax:

TimeSpan FromMinutes( Number minutes)

Parameters:

minutes: A number of minutes, accurate to the nearest millisecond.

Return Value

An object that represents minutes.

Example:


ts = TimeSpan.FromMinutes(30.5); // results in a TimeSpan of 30 minutes and 30 seconds.

FromSeconds( Number )

Returns a TimeSpan that represents a specified number of seconds where the specification is accurate to the nearest millisecond.

Syntax:

TimeSpan FromSeconds( Number seconds)

Parameters:

seconds: A number of seconds, accurate to the nearest millisecond.

Return Value

An object that represents seconds.

Example:


ts = TimeSpan.FromSeconds(30.5); // results in a TimeSpan of 30 seconds and 500 milliseconds.

FromMilliseconds( Number )

Returns a TimeSpan that represents a specified number of milliseconds.

Syntax:

TimeSpan FromMilliseconds( Number milliseconds)

Parameters:

milliseconds: A number of milliseconds.

Return Value

An object that represents milliseconds.

Example:


ts = TimeSpan.FromSeconds(30.5); // results in a TimeSpan of 30 seconds and 500 milliseconds.
Privacy Policy | Conditions Of Use

Copyright ©2014 Codecore Technologies, All rights reserved.