[英]Error:string was not recognized as a valid datetime error in c#
Error:string was not recognized as a valid datetime error in c#
错误:在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. 这是DateTime.ParseExact方法的描述。
An overview of custom date and time format strings can be found here . 可在此处找到自定义日期和时间格式字符串的概述。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.