与生产计算机相比,本地计算机上的日期时间格式不同 [英] Datetime format different on local machine compared to production machine
问题描述
在我的其中一个页面上,我显示了一个日期时间(来自数据库),并且在我的本地计算机上将其正确格式化为英国日期时间(dd-mm-yyyy).但是,当我将其部署到服务器时,它将恢复为美国格式(mm-dd-yyyy).有谁知道何时会发生这种情况?
On one of my pages I display a datetime (from a database) and it is formatted correctly as a UK date time (dd-mm-yyyy) on my local machine. However when I deploy it to a server it reverts to American format (mm-dd-yyyy). Does anyone have any idea of when this might be happening?
这可能不在stackoverflow的范围内,但我已经检查了服务器设置,并且在区域设置中似乎所有内容都设置为UK.
This might be outside the scope of stackoverflow but I've check the server settings and everything seems to be set as UK in the regional settings.
谢谢
推荐答案
您可以在web.config中设置UI文化:
You could set the UI culture in your web.config:
<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"
culture="en-GB"
uiCulture="en-GB" />
或使用 [DisplayFormat]
属性添加到视图模型的特定属性上:
or use the [DisplayFormat]
attribute on a particular property of your view model:
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd-mm-yyyy}")]
public DateTime Date { get; set; }
这篇关于与生产计算机相比,本地计算机上的日期时间格式不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!