Kendo datepicker acting weired for different computers on two different timezone

牧云@^-^@ 提交于 2019-12-02 05:46:19
Jarosław Kończak

Try to add this code at top of your page before you gonna render any kendo widget:

kendo.culture("en-GB");

It should forced kendo widgets to work in all location using en-GB culture.

If you're using ASP.MVC I recommend add it in "_Layout.cshtml" like:

<head>
...

    <script src="@Url.Content("~/Scripts/jquery/jquery-1.8.2.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Kendo/js/kendo.all.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Kendo/js/kendo.aspnetmvc.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Kendo/js/cultures/kendo.culture.pl-PL.min.js")"></script>
    <script src="@Url.Content("~/Kendo/js/cultures/kendo.culture.en-GB.min.js")"></script>
    <script src="@Url.Content("~/Kendo/js/cultures/kendo.culture.de-DE.min.js")"></script>

    <script type="text/javascript">
        kendo.culture("en-GB");
    </script>

    //widgets create scripts for your views if you write it here
</head>

Detail on globalization can be found on this link:

http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/globalization
Mahib

If your intention is to convert the date into your desired format "dd/MM/yyyy" and if your kendo grid is not providing you the correct result in different places, create your own. Some thing like this.

In Json:

var FixedDateFormat = "PlodDate: '" + (Date.getUTCDate() + 1) + "/" + (Date.getUTCMonth() + 1) + "/" + Date.getUTCFullYear() + " 00:00:00";

Here I have added 1 on Date and Month cause getUTCDate/Month starts from 0. As you have said in comments you are accepting the date as string and then converting that back to DateTime so I've added the time " 00:00:00".

In MVC: You probably need to do something like following to convert;

DateTime X = Convert.ToDateTime(PlodDate);

UPDATE

I've got a better solution for you on JS. You are reading datepicker value with something like this, right??

$("#YourDatePickerName").data("kendoDatePicker").value()

Here you can tell your browser what local you want to use like the following

$("#YourDatePickerName").data("kendoDatePicker").value().toLocaleString("en-GB");

Which will generate exact same result for every culture.

Further Update

If you want to do it Kendo's way then you can use kendo.toString(). You can check it here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!