ManagementDateTimeConverter.ToDateTime(String) 方法
定义
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 格式表示日期时间的字符串。A string representing the datetime in DMTF format.
返回
DateTime,它表示给定的 DMTF 日期时间。A DateTime that represents the given DMTF datetime.
示例
下面的示例将 DMTF 日期时间字符串转换为 DateTime 。The following example converts a DMTF datetime string into a 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
注解
WMI 中的日期和时间表示为 DMTF 日期时间格式。Date and time in WMI is represented in DMTF datetime format. 此格式在 WMI SDK 文档中进行了介绍。This format is explained in WMI SDK documentation. DMTF datetime 字符串具有此 datetime 字符串表示的 UTC 偏移量。A DMTF datetime string has an UTC offset which this datetime string represents. 在转换到期间 DateTime ,UTC 偏移量用于将日期转换为当前时区。During conversion to DateTime, the UTC offset is used to convert the date to the current time zone. 根据 DMTF 格式,特定字段可以用字符 "*" 表示。According to DMTF format, a particular field can be represented by the character '*'. 这会转换为 MinValue 可以在中表示的此字段的值 DateTime 。This will be converted to the MinValue value of this field that can be represented in DateTime.
.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.