Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含文本的文本框
18/1/2013
我想将此文本作为类型日期时间。我试过使用特定的代码
Convert.ToDateTime(DateTime.ParseExact(TxtStartDate.Text.Trim(), "dd/MM/yyyy", null));
但它抛出一个异常
String was not recognized as a valid DateTime.
利用
var date = DateTime.ParseExact(TxtStartDate.Text.Trim(), "d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture);