字符串 yy-MM-dd HH:mm:ss.SSS 在 C# 中转换为日期时间

String yy-MM-dd HH:mm:ss.SSS convert to datetime in C#

如何在 c# 中将此字符串 yy-MM-dd HH:mm:ss.SSS 转换为日期时间?

您可以使用您期望收到的 DateTime.ParseExact() method and define the exact format string :

// This will parse a DateTime object using the "yy-MM-dd HH:mm:ss.fff" format 
var date = DateTime.ParseExact(input,"yy-MM-dd HH:mm:ss.fff", null);

这假设 Y 字符将代表两位数的年份,而您要查找的 S 字符将被视为小数秒,已转换为 yf 格式。

例子

你可以see a working example of this here.