DateTimePicker日期格式怪异 [英] DateTimePicker Date Format Weirdness

查看:100
本文介绍了DateTimePicker日期格式怪异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单上有一个DateTimePicker控件,显示英国格式的日期

格式(年/月/日)。


但是,在我的代码中,dtpStartDate.Value以美国格式提供日期,但

dtpStartDate.Value.ToString()以所需的英国格式提供日期!


有任何想法吗?所有系统区域设置都设置为英国/英国设置。

I have a DateTimePicker control on my form that is displaying the date
format in UK format (dd/mm/yy).

However, in my code dtpStartDate.Value gives a date in US format, but
dtpStartDate.Value.ToString() gives the date in the required UK format!

Any ideas? All system locale settings are set to British/UK settings.

推荐答案

Ed Crowley< cu ****** @ pacbell.net>写道:
Ed Crowley <cu******@pacbell.net> wrote:
我的表格上有一个DateTimePicker控件,显示英国格式的日期
格式(年/月/日)。

然而,在我的代码dtpStartDate.Value以美国格式提供日期,但是
dtpStartDate.Value.ToString()以所需的英国格式提供日期!

任何想法?所有系统区域设置都设置为英国/英国设置。
I have a DateTimePicker control on my form that is displaying the date
format in UK format (dd/mm/yy).

However, in my code dtpStartDate.Value gives a date in US format, but
dtpStartDate.Value.ToString() gives the date in the required UK format!

Any ideas? All system locale settings are set to British/UK settings.




DateTimePicker.Value不是*任何*特定格式 - 它只是一个

DateTime。你是什​​么意思给出一个美国格式的日期?


-

Jon Skeet - < sk *** @ pobox.com> ;
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件



DateTimePicker.Value isn''t in *any* particular format - it''s just a
DateTime. What do you mean by "gives a date in US format"?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too




" Jon Skeet [C#MVP ]" < SK *** @ pobox.com>在消息中写道

新闻:MP ************************ @ msnews.microsoft.c om ...

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Ed Crowley< cu ****** @ pacbell.net>写道:
Ed Crowley <cu******@pacbell.net> wrote:
我的表格上有一个DateTimePicker控件,显示英国格式的日期
格式(年/月/日)。

然而,在我的代码dtpStartDate.Value以美国格式提供日期,但是
dtpStartDate.Value.ToString()以所需的英国格式提供日期!

任何想法?所有系统区域设置都设置为英国/英国设置。
I have a DateTimePicker control on my form that is displaying the date
format in UK format (dd/mm/yy).

However, in my code dtpStartDate.Value gives a date in US format, but
dtpStartDate.Value.ToString() gives the date in the required UK format!

Any ideas? All system locale settings are set to British/UK settings.





DateTimePicker.Value不是*任何*特定格式 - 它只是一个
DateTime。你是什​​么意思以美国格式提供日期?



DateTimePicker.Value isn''t in *any* particular format - it''s just a
DateTime. What do you mean by "gives a date in US format"?




当我将DateTimePicker的值赋给DateTime变量时,它是
当我单步执行代码时,以美国格式(dd / mm / yy)
。然后,当我尝试将
作为参数传递给SQL Server存储过程时,由于日期无效(例如今天是11/25 / 2003年这不是有效的

英国约会,但是11/11/2003工作正常。



When I assign the value of the DateTimePicker to a DateTime variable, it is
in US format (dd/mm/yy) when I step through the code. When I then try and
pass this date as a parameter to a SQL Server stored procedure it falls over
as the date is invalid (for example today is 11/25/2003 which isn''t a valid
UK date, but 11/11/2003 works fine).


我的猜测是Visual Studio'内部工作正在显示,

和Visual Studio遵循美国格式,而不是国际或标准格式。

(例如,周枚举从星期日开始,尽管有标准

明确指出星期一是一周的第一天)


你在某处输出结果时是获得美国格式,还是仅在
$ b时$ b调试?

如Jon所述,Value返回一个DateTime对象,该对象可以是任何

格式,但本身应该是本地独立的。

-

使用M2,Opera的革命性电子邮件客户端: HTTP:// www.opera.com/m2/
My guess is that Visual Studio''s internal workings are showing through,
and Visual Studio follows US formats, not international or standard ones..
(For instance week enumeration starts with sunday, despite that standards
clearly state monday to be first day of a week)

Are you getting US formats when outputting result somewhere, or only while
debugging?
As mentioned by Jon, Value returns a DateTime object which can be any
format but itself should be local independent.
--
Using M2, Opera''s revolutionary e-mail client: http://www.opera.com/m2/


这篇关于DateTimePicker日期格式怪异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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