开发者

DateTime is being interpreted as two different formats

I have an MVC application which allows appointment booking. The user can click on a slot in the diary view, which takes them to a page to select the practitioner and confirm.

The query string for this page contains a DateTime which is the time the appointment is to start. This is automatically formatted in US format by Html.ActionLink(...), like so:

/assign?date=04%2F06%2F2011%2009%3A00%3A00

This is correctly deserialised and the view reports that the appointment time will be the 6th of April. It is also stored in a hidden field in the view to be posted to the confirm action; the hidden field has the value: 04/06/2011 09:00:00, rendered by Html.HiddenFor(...). Again, looks like US format.

However, when the form gets posted, the appointment is booked for the 4th of June, presumably in开发者_JAVA百科terpreting the date as en-GB.

Why would it do that?


That might happen because your server is configured to auto detect the culture of the browser and if the browser preferred culture is en-GB that's what the server will use when binding DateTime parameters:

<globalization culture="auto" uiCulture="auto" />

You could specify it to a fixed culture:

<globalization culture="en-US" uiCulture="en-US" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜