ManagementDateTimeConverter.ToDateTime(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
public:
static DateTime ToDateTime(System::String ^ dmtfDate);
public static DateTime ToDateTime(string dmtfDate);
static member ToDateTime : string -> DateTime
Public Shared Function ToDateTime (dmtfDate As String) As DateTime
參數
- dmtfDate
- String
一個以 DMTF 格式表示日期時間的字串。
傳回
DateTime代表給定的 DMTF 日期時間。
範例
以下範例將 DMTF 日期時間字串 DateTime轉換為 。
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 的 datetime 字串有一個 UTC 偏移量,這個 datetime 字串代表了這個 UTC 偏移量。 在轉換為 DateTime時,UTC 偏移量用於將日期轉換為當前時區。 根據 DMTF 格式,特定欄位可以用字元 '*' 表示。 此值將轉換為該欄位的最小值,該值可表示為 DateTime。
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。