Angularjs-Material v. 1.2.4
Both issue can be reproduced using this demo sample: https://jsfiddle.net/Drasius/z51vgqr6/27/
Angularjs-Material md-datepicker when using ng-model-options="{timezone: 'UTC'}" option input box shows date in local time and Date Picker calendar in UTC time. There is jsfiddle script with the issue https://jsfiddle.net/Drasius/z51vgqr6/11/
<div id="app">
<div>
<strong>Date in local timezone:</strong>
{{date|date:"yyyy-MM-dd HH:mm Z"}}
</div>
<div>
<strong>Date in UTC timezone:</strong>
{{date|date:"yyyy-MM-dd HH:mm Z":"UTC"}}
</div>
</br>
<md-datepicker required ng-model="date" ng-model-options="{timezone: 'UTC'}" ></md-datepicker>
</div>
JavaScript
date = new Date().setUTCHours(23,0,0,0);
angular
.module('app', ['ngMaterial']);
angular
.bootstrap(document.querySelector('#app'), ['app']);
Found in documentation: https://docs.angularjs.org/api/ng/directive/ngModelOptions#specifying-timezones
Input-type specific options:
timezone: Defines the timezone to be used to read/write the Date instance in the model for , , ... . It understands UTC/GMT and the continental US time zone abbreviations, but for general use, use a time zone offset, for example, '+0430' (4 hours, 30 minutes east of the Greenwich meridian) If not specified, the timezone of the browser will be used. Note that changing the timezone will have no effect on the current date, and is only applied after the next input / model change.
Updated: Upgrading to angular-material 1.2.4 package version it solves initial date selection and now shown date matches, but there still is issue if you change date manually in the input field: jsFiddle sample: https://jsfiddle.net/Drasius/z51vgqr6/27/
Raised issue: https://github.com/angular/material/issues/12149
Issues:
- When initial date loaded local date is displayed in calendar and input shows correctly UTC date.
- When selecting same date few times - input box and calendar date is out of sync (in calendar local date is displayed - should be UTC) Both issues is reproducible using this codepen demo: https://codepen.io/Drasius/pen/dyZdvoM