TimeSpanConverter Class
TOC
Collapse the table of content
Expand the table of content
This documentation is archived and is not being maintained.

TimeSpanConverter Class

Provides a type converter to convert TimeSpan objects to and from other representations.

For a list of all members of this type, see TimeSpanConverter Members.

System.Object
   System.ComponentModel.TypeConverter
      System.ComponentModel.TimeSpanConverter

[Visual Basic]
Public Class TimeSpanConverter
   Inherits TypeConverter
[C#]
public class TimeSpanConverter : TypeConverter
[C++]
public __gc class TimeSpanConverter : public TypeConverter
[JScript]
public class TimeSpanConverter extends TypeConverter

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

This converter can only convert a TimeSpan object to and from a string.

For more information about type converters, see the TypeConverter base class and Implementing a Type Converter.

Note   You should never create an instance of a TimeSpanConverter. Instead, call the GetConverter method of TypeDescriptor. For more information, see the examples in the TypeConverter base class.

Example

[Visual Basic, C#, C++] The following sample converts a variable of type TimeSpan to a string, and vice versa. Both variables are represented in Ticks format.

[Visual Basic] 
Dim ts As New TimeSpan(133333330)
Dim myTSStr As String = "5000000"
Console.WriteLine(TypeDescriptor.GetConverter(ts).ConvertTo(ts, GetType(String)))
Console.WriteLine(TypeDescriptor.GetConverter(ts).ConvertFrom(myTSStr))

[C#] 
TimeSpan ts=new TimeSpan(133333330);
string myTSStr = "5000000";
Console.WriteLine(TypeDescriptor.GetConverter(ts).ConvertTo(ts, typeof(string))); 
Console.WriteLine(TypeDescriptor.GetConverter(ts).ConvertFrom(myTSStr));    

[C++] 
TimeSpan ts(133333330);
String* myTSStr = S"5000000";
Console::WriteLine(TypeDescriptor::GetConverter(__box(ts))->ConvertTo(__box(ts), __typeof(String)));
Console::WriteLine(TypeDescriptor::GetConverter(__box(ts))->ConvertFrom(myTSStr));

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

TimeSpanConverter Members | System.ComponentModel Namespace

Show:
© 2016 Microsoft