ManagementDateTimeConverter.ToDmtfTimeInterval(TimeSpan) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將指定的 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 的 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 安全性
完全信任立即呼叫者。 這個成員無法供部分信任的程式碼使用。 如需詳細資訊,請參閱 使用部分信任程式代碼的連結庫。