输入字符串不是有效的日期时间 [英] Input string is not a valid datetime
问题描述
大家好,
i同意它的一个蹩脚的问题,可以通过谷歌获得大量的在线资源,我真的想找到正确的答案,因为它真的让我感动坚果
情景是,我需要设置&保存&将日期时间显示为dd / MM / yyyy,我已经将文化更改为en-US,并将生成服务器中的Dateformat更改为dd / MM / yyyy,并通过代码传递以下代码
Hi Guys ,
i agree its a lame question and can get lots of resource online via google , i really want to find the correct answer as it really driving me nuts
The scenario is , i need to set & save & display the datetime to dd/MM/yyyy , i have already change the culture to en-US and the Dateformat to dd/MM/yyyy in the production server and have via code i am passing the below code
DateTime uploadedOn = DateTime.ParseExact(System.DateTime.Now.ToShortDateString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
drDocuments["UploadedOn"] = uploadedOn.ToShortDateString();
每当我尝试我的开发系统时,它的工作原理并假设它是固定的,我部署到uat和生产,但是给出错误
whenever i try on my developement system it works and assuming that its fixed , i deploy to uat and production , but there is giving the error
Input string is not a valid datetime
i确保两者的区域设置机器我的开发和生产服务器是一样的,任何人都可以告诉我哪里出错了,或任何建议或adivce将帮助我克服这个问题,请真的需要专家帮助,我已经投降,最后转向专家意见,希望CP会员可以帮助
i have made sure that regional settings on both the machine my developement and production server are same , can anybody please advise where i am going wrong , or any suggestion or adivce which will help me to overcome the issue, please , really need experts help , i have surrendered and finally turned to expert opinion , Hope CP Members can help
推荐答案
试试这个:
Try this:
DateTime uploadedOn = DateTime.ParseExact("1/9/2009", "M/d/yyyy", new CultureInfo("en-US"));
hi buddy尝试一次
DateTime uploadedOn = DateTime.ParseExact(System.DateTime.Now.ToString(MM / dd / yyyy),dd / MM / yyyy,CultureInfo.InvariantCulture);
drDocuments [UploadedOn] = uploadedOn.ToShortDateString();
默认日期时间格式sql是-mm / dd / yyyy,这样你就会收到错误
可以解决你的问题..
hi buddy try it once
DateTime uploadedOn = DateTime.ParseExact(System.DateTime.Now.ToString("MM/dd/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture);
drDocuments["UploadedOn"] = uploadedOn.ToShortDateString();
default date time format in sql is- mm/dd/yyyy, so that you getting error
May it solve ur problem..
这篇关于输入字符串不是有效的日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!