Kentico-无法将DateTime保存在"DD/MM/YYYY"中格式 [英] Kentico - Not able to save the DateTime in "DD/MM/YYYY" format

查看:83
本文介绍了Kentico-无法将DateTime保存在"DD/MM/YYYY"中格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用版本12.0.59的Kentico 12 MVC网站,默认区域性设置为"en-AU".

I am working on Kentico 12 MVC Site in version 12.0.59 and default culture set to "en-AU".

我创建了一个名为样本表单"的表单.

I have created a Form named "Sample Form".

当我尝试将日期时间保存为"MM/DD/YYYY"或"YYYY/MM/DD"时,它可以正常工作并将数据保存在表单的数据库中.

When I am trying to save the datetime in either "MM/DD/YYYY" or "YYYY/MM/DD" it works correctly and saves the data in the database for the form.

但是当我尝试以"DD/MM/YYYY"格式保存日期时间并单击提交"按钮以将数据保存到数据库中时,它显示如下错误:

But when I try to save the datetime in format "DD/MM/YYYY" and click on Submit button to save the data in database, it shows the error as follows:

有人可以建议吗?

谢谢

推荐答案

一个可能的原因是代码中当前线程缺少区域性设置.仅在Kentico管理界面中选择默认区域性"en-AU"是不够的.在处理请求之前的代码中,还应该为线程设置所需的区域性:

One potential reason for that is a missing culture setting for the current thread in the code. It is not enough just to select the default culture "en-AU" in the Kentico admin interface. In the code before processing your request you should set the desired culture for the thread as well:

Thread.CurrentThread.CurrentUICulture = yourDefaultOrSelectedCulture;
Thread.CurrentThread.CurrentCulture = yourDefaultOrSelectedCulture;

在Kentico示例Dancing Goat MVC网站中,您可以在 MultiCultureMvcRouteHandler.cs 代码文件中看到此实现.

In Kentico example Dancing Goat MVC website you can see this implemented in MultiCultureMvcRouteHandler.cs code file.

这篇关于Kentico-无法将DateTime保存在"DD/MM/YYYY"中格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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