I have a string which is a representation of DateTime:
string dateTime = "20110801";
Now I want to use DateTime.Parse(dateTime);
It throws an Exception stating that dateTime is not in a valid format.
Can anyone tell me how it can be done??
您需要使用格式字符串yyyyMMdd
调用ParseExact
。
You can use DateTime.ParseExact , which takes in the format as a parameter.
For example:
DateTime.ParseExact("20110801", "yyyyMMdd", CultureInfo.CurrentCulture)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.