简体   繁体   中英

Error:string was not recognized as a valid datetime error in c#

Error:string was not recognized as a valid datetime error in c#

But I am using same code using in server system their working perfectly but in my local I got error so kindly

MTL_REQD_BY_DATE = Convert.ToDateTime(mtlReqDate.Split('-')[1] + "-" + mtlReqDate.Split('-')[0] + "-" + mtlReqDate.Split('-')[2])

日期格式在本地计算机上必须不同。

It seems that the cultures of your system and the server are different.

Use the following approach for precise control:

DateTime date = DateTime.ParseExact(mtlReqDate, "dd-MM-yyyy", CultureInfo.Current);

Here is the description of the DateTime.ParseExact method.

An overview of custom date and time format strings can be found here .

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