2

I am using angularJS ui-bootstrap timepicker on client-side and ASP MVC Web API on server-side:

<timepicker ng-model="formData.NotificationSendingTime"></timepicker>

Client gets NotificationSendingTime from server in format like this: 2015-04-23T20:00:00.

But different browsers show different time: Internet Explorer shows 20:00 (right), Chrome shows 23:00 (wrong). As I understand, Chrome changes the time according to my local timezone. So I've written angularJS filter to convert date to iso format:

filter('toIso', [function() {
    return function(dateTime) {
        var localDate = new Date(dateTime);
        var localTime = localDate.getTime();
        var localOffset = localDate.getTimezoneOffset() * 60000;
        var isoDate = new Date(localTime + localOffset);

        return isoDate.toISOString();
    };
}]);

And use it in my controller (setting of $scope.formData is not shown in code below):

value.NotificationSendingTime = $filter('toIso')(value.NotificationSendingTime);

After applying the filter Internet Explorer shows 17:00 (wrong), Chrome shows 20:00 (right).

So my question is what do I do to achieve the same value in timepickers in different browsers? Thanks.

Vitone
  • 498
  • 1
  • 7
  • 19
  • 1
    You need to pass the timezone information `2015-05-23T20:00:00+03:00` in order to get correct rendering. See [javascript timezone question](http://stackoverflow.com/questions/7629286/annoying-javascript-timezone-adjustment-issue) for more details. – Pekka Apr 24 '15 at 08:42
  • @Pekka, you're right, information about timezone should be added. So on server-side I added property that returns NotificationSendingTime.Value.ToLocalTime() and all browsers displays the same values. How can I configure my Web-Api to serialize DateTime with information about timezone? – Vitone Apr 24 '15 at 11:58

0 Answers0