根据地区验证日期 [英] Validate date depending on region

查看:80
本文介绍了根据地区验证日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这是在英国的编译和美国的服务器上托管的应用程序MVC4。在我的模型我有需要日期字段。

I have an MVC4 app which is compiled in the UK and hosted on a US server. In my model I have a date field which is required.

是一个日期选择器,在选择日期,将设置一个日期是英国的格式为DD / MM / YYYY如23/12/2013。在提交表单的应用程序抛出,因为它并不指望格式验证错误。

Attached to this field is a date picker, on selecting a date it will set a date to be UK format "DD/MM/YYYY" e.g. 23/12/2013. On submitting the form the application throws a validation error as it does not expect the the format.

在MVC4我该怎么办:

In MVC4 how do I:


  1. 接受两个日期格式,即覆盖的日期格式?我已经设置了日期格式,但不能指定多种日期格式

  2. 服务器端我保存日期使用LINQ数据库。这也将引发错误的格式不正确。我怀疑我将需要转换为英国的日期?

  3. 加载时的细节把日期以正确的格式取决于用户的位置

  4. 检测到用户服务器端的位置?

有没有人有任何的细节如何非常根据用户的全球化验证?

Has anyone got any details on how to very validation based on globalisation of the user?

感谢

推荐答案

你的 web.config中添加以下段

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

和阅读code作为DateTime格式的日期。这不应该给你一个问题。

and read your date in code as DateTime format. that should not give you a problem.

另一种方法是在你的服务器端code阅读THA日期总是像DateTimeUTC,当你永远在屏幕上显示的日期,使用 .ToLocalTime()

Another way is to in you server side code read tha date always as DateTimeUTC and when ever you display the date on the screen, use .ToLocalTime()

这篇关于根据地区验证日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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