ManagementDateTimeConverter.ToDmtfTimeInterval(TimeSpan) 方法

定义

将给定的 TimeSpan 转换为 DMTF 时间间隔。Converts a given TimeSpan to DMTF time interval.

public:
 static System::String ^ ToDmtfTimeInterval(TimeSpan timespan);
public static string ToDmtfTimeInterval (TimeSpan timespan);
static member ToDmtfTimeInterval : TimeSpan -> string
Public Shared Function ToDmtfTimeInterval (timespan As TimeSpan) As String

参数

timespan
TimeSpan

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

返回

String

一个字符串,它表示给定的 TimeSpan 的 DMTF 时间间隔。A string that represents the DMTF time interval for the given TimeSpan.

示例

下面的示例将给定的转换 TimeSpan 为 DMTF 时间间隔。The following example converts a given TimeSpan to DMTF time interval.

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 日期时间格式。Time interval in WMI is represented in DMTF datetime format. 此格式在 WMI SDK 文档中进行了介绍。This format is explained in WMI SDK documentation. DMTF 中的最低精度为微秒;在中 TimeSpan ,最低精度为 Ticks ,相当于100毫微秒。The lowest precision in DMTF is microseconds; in TimeSpan, the lowest precision is Ticks, which is 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.

适用于