将字符串转换为DateTime对象 [英] Converting a string to DateTime object
本文介绍了将字符串转换为DateTime对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想一个字符串以特定格式转换为的DateTime
。
我的特定字符串格式 DD-MM-YYYY
我不能做任何字符串操作。
这是代码我现在:
的DateTime convertedDate = DateTime.Parse(stringInput) ;
解决方案
看来你要静态的 ParseExact
方法,你可以指定。实际的日期时间格式为:
VAR convertedDate = DateTime.ParseExact(输入DD-MM-YYYY,NULL);
(根据上下文,你可能还需要指定 CultureInfo.InvariantCulture
而不是空
/电流文化作为一个参数。)
I want to convert a string in a specific format to a DateTime
.
My specific string format is "dd-mm-yyyy
".
I cannot do any string manipulations.
This is the code I have right now:
DateTime convertedDate = DateTime.Parse(stringInput);
解决方案
It seems you want the static ParseExact
method to which you can specify the actual date-time format.
var convertedDate = DateTime.ParseExact(input, "dd-MM-yyyy", null);
(Depending on the context, you may also want to specify CultureInfo.InvariantCulture
instead of null
/current culture as an argument.)
这篇关于将字符串转换为DateTime对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文