Unable to parse DateTime from a string

前端 未结 6 2058
时光说笑
时光说笑 2020-12-22 10:47
string dt = \"10/25/2010 11:40:05 PM\";
var currentThread = Thread.CurrentThread.CurrentCulture; //ru-RU
DateTime dateTime = DateTime.Parse(dt); //Exception!
         


        
6条回答
  •  旧巷少年郎
    2020-12-22 11:18

    Try using ParseExact instead:

    DateTime myDate = DateTime.ParseExact("10/25/2010 11:40:05 PM", "MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
    

提交回复
热议问题