我想将特定格式的字符串转换为 DateTime
。
我的特定字符串格式是“dd-mm-yyyy
”。
我无法进行任何字符串操作。
这是我现在的代码:
DateTime convertedDate = DateTime.Parse(stringInput);
最佳答案
看来你想要静态的 ParseExact
您可以指定实际日期时间格式的方法。
var convertedDate = DateTime.ParseExact(input, "dd-MM-yyyy", null);
(根据上下文,您可能还想指定 CultureInfo.InvariantCulture
而不是 null
/current culture 作为参数。)
关于c# - 将字符串转换为 DateTime 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3072596/