不同服务器之间的日期格式不匹配(XML列) [英] Date formats mismatch between different servers (XML column)
问题描述
过去两天,我在SQL中遇到有关日期格式的问题.
I am facing a problem for past two days with regard to the date format in SQL.
我已经在ASP.NET中开发了一个应用程序,并将其部署在生产服务器中.我将数据持久化到一个表中,该表具有一个带有
I have developed a application in ASP.NET and have deployed it in production server. I am persisting data into a table which has an xml column with date feilds like
--一些约会时间--
当我从本地主机运行该应用程序(或在我的计算机中部署该应用程序)时,该日期将以24小时时间格式保存
When I run the application from localhost ( or deploy the application in my computer) the date is persisted in in 24 hours time format
例如:2009年8月15日14:30:00
For eg :15/08/2009 14:30:00
并且当我运行生产服务器中部署的相同应用程序时,数据将以12小时时间格式保存
and when I run the same application deployed in the production server the data is persisted in 12 hours time format
例如:15/08/2009 2:30:00 PM
For eg: 15/08/2009 2:30:00 PM
注意:保留数据时,我没有在应用程序代码中指定任何格式.
Note: I am not specifying any format in the application code when persisting data.
以下是我尝试过的内容:
The following is what I have tried :
-
检查到我的计算机和Web服务器的区域设置以及格式是否相同(h:mm:ss tt)
Checked regional settings of my computer and the webserver and format is the same (h:mm:ss tt)
已检查了我的计算机和Web服务器的区域性信息,并且相同.(zh-CN)
Have checked the culture info of both my computer and webserver and it is the same. (en-AU)
在我的计算机的IIS属性中,通过编辑配置,设置了与Web服务器相同的区域性.
In my computer's IIS Properties I have set the same culture of the webserver by Editing the configuration.
当从我的计算机和生产Web服务器上同时保存时,同一表的日期列中的日期以一致的格式(24小时格式)存储.
The dates in date columns of the same table are stored in consisntent format (24 hr format) when persisted from both my computer and the production webserver.
例如:2009-10-28 14:00:49.000
For eg: 2009-10-28 14:00:49.000
日期时间仍然以不同的格式存储.我无法确定应用程序在持久化时从何处采用格式.
Still the date time is stored in different formats. I am unable to figure out from where the application is taking the format when persisting.
我终于找到了这个问题的根本原因.我希望将其发布,以防万一有人遇到同样的问题,这可能会对他们有所帮助.
I finally found the root cause for this problem. I would like to post it just in case someone faces this same problem this might help them.
转到regedit.选择Controlpanel-> international-> sTimeFormat并验证给定的时间格式.
Go to regedit. Select Controlpanel -> international -> sTimeFormat and verify the time format given.
在我的计算机中,时间格式为HH:mm:ss,而在服务器中,时间格式为hh:mm:ss tt是主要问题.我已将服务器中的格式更改为HH:mm:ss,它的工作原理很完美:)
In my computer, the time format is HH:mm:ss and in server it is hh:mm:ss tt that was the main problem. I have changed the format in server to HH:mm:ss and it works perfect :)
有关详细信息,请参考此链接./p>
Please refer to this link for details.
推荐答案
尝试将以下内容添加到网站的web.config中:
Try add the following to the web.config of your website:
<system.web>
<globalization culture="en-ZA" uiCulture="en-ZA"/>
</system.web>
将"en-ZA"替换为您需要的特定文化.这样可以确保不使用浏览器的区域性设置.
Replace "en-ZA" with the specific culture you require. The will ensure that the browsers culture settings will not be used.
这篇关于不同服务器之间的日期格式不匹配(XML列)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!