格式化字符串为日期

Jak*_*key 3 c#

我有一个字符串20100524(2010 05 24),我想将其解析为实际的日期格式.

Fre*_*örk 16

这将以安全的方式为您完成:

DateTime dateTime;
if (DateTime.TryParseExact("20100524", "yyyyMMdd", null, DateTimeStyles.None, out dateTime))
{
    // use dateTime here
}
else
{
    // the string could not be parsed as a DateTime
}
Run Code Online (Sandbox Code Playgroud)


Ovi*_*rar 6

DateTime.Parse和Datetime.ParseExact是你的朋友.