将 WMI Win32_OperatingSystem InstallDate 转换为 mm/dd/yyyy 格式 (C# - WPF) [英] Convert WMI Win32_OperatingSystem InstallDate to mm/dd/yyyy format (C# - WPF)
本文介绍了将 WMI Win32_OperatingSystem InstallDate 转换为 mm/dd/yyyy 格式 (C# - WPF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何将日期和时间从 20100131022308.000000-360 转换.
I am wondering how you would convert the date and time from 20100131022308.000000-360.
我已经尝试了一段时间了,但似乎无处可去.
I've been trying to figure it out for a while now and I can't seem to get anywhere.
我在 WPF 应用程序中使用 C#.
I am using C# in a WPF Application.
推荐答案
System.Management.ManagementDateTimeConverter 类旨在解决您的问题.使用它的 ToDateTime() 方法.它正确解析字符串中的毫秒和 UTC 偏移量:
The System.Management.ManagementDateTimeConverter class was made to solve your problem. Use its ToDateTime() method. It properly parses milliseconds and the UTC offset in the string:
DateTime dt = System.Management.ManagementDateTimeConverter.ToDateTime("20100131022308.000000-360");
Console.WriteLine(dt);
输出:2010/1/31 2:23:08 上午
Output: 1/31/2010 2:23:08 AM
这篇关于将 WMI Win32_OperatingSystem InstallDate 转换为 mm/dd/yyyy 格式 (C# - WPF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文