字符串在Windows应用程序C#中未被识别为有效的日期时间 [英] String not recognized as a valid datetime in windows application C#

查看:93
本文介绍了字符串在Windows应用程序C#中未被识别为有效的日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我的电脑默认日期时间格式是Hijri。



我创建了一个c#中的windows应用程序。 DateTime.Now在哪里给我hijri datetime,在那里我正在寻找Gregorian dateTime。



我尝试了什么:



DateTime dt = DateTime.ToString(new CultrueInfo(en-US));



I在基于Web的应用程序中解决了同样的问题。所以,我在web.config文件中添加了这个代码,解决了这个问题。



Dear All,

My PC default datetime format is Hijri.

I have created one windows application in c#. Where DateTime.Now is giving me hijri datetime, where as i'm looking for the Gregorian dateTime.

What I have tried:

DateTime dt = DateTime.ToString(new CultrueInfo("en-US"));

I had phased the same problem in Web based application. So, I have added this code in the web.config file, which solved the problem.

<globalization culture="en-US" uiCulture="en-US" />





我可以在app.config中做同样的事情吗?





请帮帮我们。





谢谢



Can i do this same thing in app.config also?


Please help me guys.


Thanks

推荐答案

您的错误消息与该代码无关:

Your error message does not relate to that code:
String not recognized as a valid datetime

意味着某处,一个字符串正在转换为DateTime,而不是从DateTime转换为字符串。



从调试器开始,并查看生成异常的代码 - 它可能类似于 Convert.ToDateTime ,您需要准确查看您尝试转换的字符串包含的内容。找到它时,将代码更改为使用DateTime.TryParse或甚至DateTime.TryParseExact,并在出现错误时报告或记录错误。



我们不能为您做到这一点 - 错误来自数据库或类似的错误,我们无法访问该代码或其他代码。

Means that somewhere, a string is being converted to a DateTime, not converted from a DateTime to a string.

Start with the debugger, and look at the code that generates the exception - the chances are it's something like Convert.ToDateTime, and you need to look at exactly what the string you are trying to convert contains. When you find it, change the code to use DateTime.TryParse or even DateTime.TryParseExact and report or log errors when they occur.

We can't do that for you - the chances are the error comes from a database or similar, and we have no access to that or your other code.


Hi abdul subhan mohammed



希望这能帮助你

Windows中的阿拉伯语日历日期到英语日历日期表格C# [ ^ ]


这篇关于字符串在Windows应用程序C#中未被识别为有效的日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆