在我的 ASP.NET MVC 应用程序中,ModelState 始终无效,并显示以下错误消息:“值‘5/23/2015 7:29:37 AM’对于注册日期无效。”
我正在尝试针对波斯文化本地化我的应用,因此我在 中将
。不过,uiCulture
和 culture
设置为 fa-IR
>web.configDateTime.Now
不会返回本地化日期。
全局化DateTime
的正确方法是什么?我应该将本地化日期存储在数据库中吗?还是说本地化版本只是为了浏览?
看来我应该将本地化版本存储在数据库中,我怎样才能获得波斯文化的本地化版本?
更新:
看来我无法直接获取当前的波斯日期,我必须按照 MSDN 中所述进行转换。 :
You cannot use a PersianCalendar object as the default calendar for a culture. The default calendar is specified by the CultureInfo.Calendar property and must be one of the calendars returned by the CultureInfo.OptionalCalendars property. Currently, the PersianCalendar class is not an optional calendar for any culture supported by the CultureInfo class and consequently cannot be a default calendar.
我如何知道哪个组件添加了错误消息以及如何修复它?
最佳答案
我建议您在客户端本地化日期,而不是在服务器或数据库端。这样,您就不再受特定文化的束缚。例如,您的日期可以这样表示:“2015-05-23T7:29:37Z”。
我还建议您以 UTC 格式保存并发送日期时间。
关于c# - ASP.NET MVC 和 SQL SERVER 中的日期时间全局化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30409515/