简体   繁体   English

将此自定义字符串格式转换为DateTime吗?

[英]Convert this custom string format into DateTime?

How to convert the following string 如何转换以下字符串

09/11/2011 9:40:55 pm
    20/11/2011 3:40:55 am

into C# DateTime ? 进入C#DateTime吗?

Use DateTime.ParseExact . 使用DateTime.ParseExact

string dateString = "20/11/2011 3:40:55 am";
DateTime parsedDate = DateTime.ParseExact(
   dateString,
   "dd/MM/yyyy h:mm:ss tt",
   CultureInfo.InvariantCulture);
DateTime DT_1 = new DateTime(2011, 11, 9, 21, 40, 55);
DateTime DT_2 = new DateTime(2011, 11, 20, 15, 40, 55);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM