ManagementDateTimeConverter.ToDmtfTimeInterval(TimeSpan) 方法

定义

将给定的 TimeSpan 转换为 DMTF 时间间隔。

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 时间间隔的日期时间。

返回

一个字符串,它表示给定的 TimeSpan 的 DMTF 时间间隔。

示例

以下示例将给定 TimeSpan 的时间间隔转换为 DMTF 时间间隔。

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

注解

DMTF 中的最低精度为微秒;中 TimeSpan,最低精度为 Ticks,相当于 100 纳秒。 在转换期间, Ticks 转换为微秒,并舍入到最接近的微秒。

.NET Framework 安全性

对直接调用方的完全信任。 此成员不能由部分信任的代码使用。 有关详细信息,请参阅 使用部分受信任的代码中的库

适用于