Вопрос

In my MVC application I am storing dates in UTC. In my view I am doing this to show the dates in date time pickers in local time

<div class="datetimepicker">@(Html.Kendo().DateTimePickerFor(m => m.StartDateTime).Value(Model.StartDateTime.ToLocalTime()))</div>

The problem is that when the datetimes arereturned in the post methods back to the server they are returned in local time. Is there a way from the view to return the datetimes in UTC?

Это было полезно?

Решение

Hi datetimepicker in kendo i dono abt it,but just a thought if u can get the value from datetimepicker and pass through a function as below which converts to UTC and then send it to server , i believe ur task is complete..sry if i am wrong...

function convertToUtc(str) {
    var date = new Date(str);
    var year = date.getUTCFullYear();
    var month = date.getUTCMonth()+1;
    var dd = dategetUTCDate();
    var hh = date.getUTCHours(); 
    var mi = date.getUTCMinutes();
    var sec = date.getUTCSeconds();

    // 2010-11-12T13:14:15Z

    theDate = year + "-" + (month [1] ? month : "0" + month [0]) + "-" + 
              (dd[1] ? dd : "0" + dd[0]);
   theTime = (hh[1] ? hh : "0" + hh[0]) + ":" + (mi[1] ? mi : "0" + mi[0]);
    return [ theDate, theTime ].join("T");
 }

Другие советы

Your question is a good one and the approach that we suggest is covered in this code library article.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top