System.TimeSpan.FromSeconds Method

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

Syntax

public static TimeSpan FromSeconds (double value)

Parameters

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

Returns

An object that represents value.

Exceptions

TypeReason
OverflowExceptionThe TimeSpan represented by value is greater than TimeSpan.MaxValue or less than TimeSpan.MinValue.
ArgumentException value is equal to double.NaN.

Remarks

The value parameter is converted to milliseconds, which is converted to ticks, and that number of ticks is used to intialize the new TimeSpan. Therefore, value will only be considered accurate to the nearest millisecond. Note that, because of the loss of precision of the double data type, this can generate an OverflowException for values that are near but still in the range of either TimeSpan.MinValue or TimeSpan.MaxValue, This is the cause of an OverflowException, for example, in the following attempt to instantiate a TimeSpan object.

code reference: System.TimeSpan.FromMinutes#5

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0