文本框中的日期更改格式
我有一个支持 4 种不同语言的应用程序 (asp.net 3.5)。与其他文化变化一起,日期格式必须与报告页面上的当前文化相匹配。
我们将每个文本框的日期格式设置为:
string date = DateTime.Today.ToString("d"); //returns the date portion only
textbox1.Text = date;
textbox2.Text = date;
etc...
当用户选择西班牙语或英国英语时,格式应为 dd/mm/yyyy。但是,然后我导航到它以 mm/dd/yyyy 格式显示的页面。回发后,它会显示 dd/mm/yyyy。另一次回发后,它会切换到 mm/dd/yyyy 格式,然后不断地切换。
我已经对此进行了调试,我发现应用程序的区域性是正确的,并且日期格式正确地返回给我,但是当它显示时,它显示不正确。
有谁见过这个或知道发生了什么?
I have an application (asp.net 3.5) that support 4 different languages. Along with other cultural changes, the date formats must match the current culture on out reporting pages.
We set the date formats of each of the textboxes like:
string date = DateTime.Today.ToString("d"); //returns the date portion only
textbox1.Text = date;
textbox2.Text = date;
etc...
When the user selects Spanish or British English the format should be dd/mm/yyyy. However, then I navigate to the page it displays in mm/dd/yyyy. After a postback it then displays dd/mm/yyyy. After another postback it switches to the mm/dd/yyyy format and on and on.
I have debugged through this and I see that the culture is correct for the application and the date formats are returned to me correctly, yet when it displays, it displays incorrectly.
Has anyone ever seen this or know what is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您仅更改一页的区域性,则应覆盖问题中的 aspx 页面的
InitializeCulture
:如果您想为整个应用程序设置区域性,请在全局中使用
Application_BeginRequest
。阿萨克斯。您当然可以将 en-US 更改为适合您的用户的正确文化。
If you are changing culture for just one page you should override
InitializeCulture
for the aspx pages in questions:If you want to set culture for the whole app, use
Application_BeginRequest
in global.asax.You would of course change en-US to the correct culture for your users.