简体   繁体   中英

String was not recognized as a valid DateTime while converting specific date string to datetime

I am getting error while converting string to datetime.

string dateStarted= "Wed Nov 27 2019 20:37:46 GMT+0700 (Indochina Time)";
DateTime startedDate = DateTime.Parse(dateStarted);

You should use ParseExact to convert string to datetime

var date = DateTime.ParseExact(
                    "Wed Nov 27 2019 20:37:46 GMT+0700 (Indochina Time)",
                   "ddd MMM dd yyyy HH:mm:ss 'GMT+0700 (Indochina Time)'",
                    CultureInfo.InvariantCulture);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM