我有一个string
包含yyyyMMdd格式的日期.我想使用ConvertTo.DateTime()
方法或任何其他简单方法将该日期转换为系统日期格式.
string value = "19851231"; //yyyyMMdd
DateTime dateTime = 1985/12/31;
Run Code Online (Sandbox Code Playgroud)
Bro*_*ass 144
string time = "19851231";
DateTime theTime= DateTime.ParseExact(time,
"yyyyMMdd",
CultureInfo.InvariantCulture,
DateTimeStyles.None);
Run Code Online (Sandbox Code Playgroud)
看一下静态方法DateTime.Parse()
和DateTime.TryParse()
。它们将允许您传入日期字符串和格式字符串,并获取 DateTime 对象作为返回。
http://msdn.microsoft.com/en-us/library/6fw7727c.aspx