ManagementDateTimeConverter.ToDmtfDateTime(DateTime) 方法

定义

将给定的 DateTime 转换为 DMTF 日期时间格式。Converts a given DateTime to DMTF datetime format.

public:
 static System::String ^ ToDmtfDateTime(DateTime date);
public static string ToDmtfDateTime (DateTime date);
static member ToDmtfDateTime : DateTime -> string
Public Shared Function ToDmtfDateTime (date As DateTime) As String

参数

date
DateTime

DateTime,它表示将转换为 DMTF 日期时间的日期时间。A DateTime representing the datetime to be converted to DMTF datetime.

返回

String

一个字符串,它表示给定的 DateTime 的 DMTF 日期时间。A string that represents the DMTF datetime for the given DateTime.

示例

下面的示例将给定的转换 DateTime 为 DMTF 日期时间格式。The following example converts a given DateTime to DMTF datetime format.

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 dmtfDateTime =
            ManagementDateTimeConverter.ToDmtfDateTime(DateTime.Now);

        // Converting DMTF time interval 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;
    }
}
Imports System.Management

'The sample below demonstrates the various conversions
' that can be done using ManagementDateTimeConverter class    
Class Sample_ManagementClass
    Public Overloads Shared Function Main(ByVal 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.ToDmtfDateTime(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)
        Dim dmtfTimeInt As String
        dmtfTimeInt = _
            ManagementDateTimeConverter.ToDmtfTimeInterval(ts)

        Return 0
    End Function
End Class

注解

WMI 中的日期和时间表示为 DMTF 日期时间格式。Date and time in WMI is represented in DMTF datetime format. 此格式在 WMI SDK 文档中进行了介绍。This format is explained in WMI SDK documentation. 所表示的 DMTF 日期时间字符串将与当前时区的 UTC 偏移量有关。The DMTF datetime string represented will be with respect to the UTC offset of the current time zone. DMTF 中的最低精度为微秒;在中 DateTime ,最低精度为 Ticks ,相当于100毫微秒。The lowest precision in DMTF is microseconds; in DateTime, the lowest precision is Ticks, which are equivalent to 100 nanoseconds. 在转换过程中, Ticks 转换为微秒并舍入为最接近的微秒。During conversion, Ticks are converted to microseconds and rounded off to the nearest microsecond.

.NET Framework 安全性.NET Framework Security

对直接调用方的完全信任。Full trust for the immediate caller. 此成员不能由部分信任的代码使用。This member cannot be used by partially trusted code. 有关详细信息,请参阅 从部分受信任的代码使用库For more information, see Using Libraries from Partially Trusted Code.

适用于