Gemstone Common Library
Show/Hide TOC

# TimeSpanExtensionsToElapsedTimeString Method

Converts the TimeSpan value into a textual representation of years, days, hours, minutes and seconds with the specified number of fractional digits given string array of time names.

## Definition

Namespace: Gemstone.TimeSpanExtensions
Assembly: Gemstone.Common (in Gemstone.Common.dll) Version: 1.0.173 -- Release Build+298e1c238b074757f82f41812034645402a162ed
C#
View Source Request Example

    public static string ToElapsedTimeString(
    	this TimeSpan value,
    	int secondPrecision = 2,
    	string[]? timeNames = null,
    	double minimumSubSecondResolution = 0.001
    )

VB
View Source Request Example

    <ExtensionAttribute>
    Public Shared Function ToElapsedTimeString (
    	value As TimeSpan,
    	Optional secondPrecision As Integer = 2,
    	Optional timeNames As String() = Nothing,
    	Optional minimumSubSecondResolution As Double = 0.001
    ) As String

C++
View Source Request Example

    public:
    [ExtensionAttribute]
    static String^ ToElapsedTimeString(
    	TimeSpan value,
    	int secondPrecision = 2,
    	array<String^>^ timeNames = nullptr,
    	double minimumSubSecondResolution = 0.001
    )

JavaScript
View Source Request Example

    Gemstone.TimeSpanExtensions.TimeSpanExtensions.ToElapsedTimeString = function(value, secondPrecision, timeNames, minimumSubSecondResolution);

#### Parameters

value TimeSpan
  The TimeSpan to process.
secondPrecision Int32 (Optional)
  Number of fractional digits to display for seconds.
timeNames String (Optional)
  Time names array to use during textual conversion.
minimumSubSecondResolution Double (Optional)
  Minimum sub-second resolution to display. Defaults to Milli.

#### Return Value

String
The string representation of the value of this instance, consisting of the number of years, days, hours, minutes and seconds represented by this value.

#### Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type TimeSpan. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

## Remarks

Set secondPrecision to -1 to suppress seconds display, this will force minimum resolution of time display to minutes.

timeNames array needs one string entry for each of the following names:
" year", " years", " day", " days", " hour", " hours", " minute", " minutes", " second", " seconds", "less than ".

## Example

`DateTime g_start = DateTime.UtcNow; DateTime EndTime = DateTime.UtcNow; TimeSpan duration = EndTime.Subtract(g_start); Console.WriteLine("Elapsed Time = " + duration.ToElapsedTimeString());`

## Exceptions

ArgumentOutOfRangeException | minimumSubSecondResolution is not less than or equal to Milli or minimumSubSecondResolution is not defined in Factors array.

## See Also

#### Reference

TimeSpanExtensions Class
Gemstone.TimeSpanExtensions Namespace