date.parse()错误 [英] date.parse() error

查看:193
本文介绍了date.parse()错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用date.parse()函数将格式为"mm/dd/yyyy"的字符串转换为日期.

当系统日期格式为相同格式但系统日期格式更改时,例如,它可以正常工作. "dd/MM/yyyy",那么我得到一个错误,表明该字符串无法转换为日期.

请帮助我解决此问题.

Hi,

I''m using the date.parse() function to convert a string in the format "mm/dd/yyyy" to date.

It''s working fine when the system date format is in the same format but if the system date format is changed, eg. "dd/MM/yyyy", then I''m getting an error showing that the string cannot be converted to date.

Please help me to resolve this problem.

推荐答案

使用重载的方法DateTime.Parse(string,IFormatProvider)并指定该字符串作为日期的语言环境.请参阅此处 [
Use the overloaded method DateTime.Parse(string, IFormatProvider) and specify the locale that the string date it in. See here[^]
For example, your US date format string could be
string myStringDate = "05/20/2010";
DateTime dt = DateTime.Parse(myStringDate, CultureInfo.CreateSpecificCulture("en-US"));


您可以通过CultureInfo更改系统.
您可以在两种格式之间进行解析.
您可以阅读格式并引发异常.

您可以根据自己的代码选择三种不同的方法来决定保密,因此不允许进行进一步的调查或发表意见.

也许如果您能提供更多详细信息,将会有更多帮助.
You can alter the system via CultureInfo.
You can Parse between the two formats.
You can read the format and throw an exception.

There you go, three different methods depending on your code, which you decided to keep secret, thus not allowing for further investigation or opinion.

Perhaps if you could give more details more help would be forthcoming.


这篇关于date.parse()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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