ManagementDateTimeConverter Class
Provides methods to convert DMTF datetime and time interval to CLR compliant DateTime and TimeSpan format and vice versa.
For a list of all members of this type, see ManagementDateTimeConverter Members.
System.Object
System.Management.ManagementDateTimeConverter
[Visual Basic] NotInheritable Public Class ManagementDateTimeConverter [C#] public sealed class ManagementDateTimeConverter [C++] public __gc __sealed class ManagementDateTimeConverter [JScript] public class ManagementDateTimeConverter
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.
Example
[C#] using System; using System.Management; // The sample below demonstrates the various conversions that can be done using ManagementDateTimeConverter class class Sample_ManagementDateTimeConverterClass { public static int Main(string[] args) { string dmtfDate = "20020408141835.999999-420"; string dmtfTimeInterval = "00000010122532:123456:000"; // Converting DMTF datetime to System.DateTime DateTime dt = ManagementDateTimeConverter.ToDateTime(dmtfDate); // Converting System.DateTime to DMTF datetime string dmtfDate = ManagementDateTimeConverter.ToDateTime(DateTime.Now); // Converting DMTF timeinterval to System.TimeSpan System.TimeSpan tsRet = ManagementDateTimeConverter. ToTimeSpan(dmtfTimeInterval); //Converting System.TimeSpan to DMTF time interval format System.TimeSpan ts = new System.TimeSpan(10,12,25,32,456); string dmtfTimeInt = ManagementDateTimeConverter.ToDmtfTimeInterval(ts); return 0; } } [Visual Basic] Imports System Imports System.Management 'The sample below demonstrates the various conversions that can be done using ManagementDateTimeConverter class Class Sample_ManagementClass Overloads Public Shared Function Main(args() As String) As Integer Dim dmtfDate As String = "20020408141835.999999-420" Dim dmtfTimeInterval As String = "00000010122532:123456:000" 'Converting DMTF datetime and intervals to System.DateTime Dim dt As DateTime = ManagementDateTimeConverter.ToDateTime(dmtfDate) 'Converting System.DateTime to DMTF datetime dmtfDate = ManagementDateTimeConverter.ToDateTime(DateTime.Now) ' Converting DMTF timeinterval to System.TimeSpan Dim tsRet As System.TimeSpan = ManagementDateTimeConverter.ToTimeSpan(dmtfTimeInterval) 'Converting System.TimeSpan to DMTF time interval format Dim ts As System.TimeSpan = New System.TimeSpan(10, 12, 25, 32, 456) String dmtfTimeInt = ManagementDateTimeConverter.ToDmtfTimeInterval(ts) Return 0 End Function End Class
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Management
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.Management (in System.Management.dll)
See Also
ManagementDateTimeConverter Members | System.Management Namespace