logbon72 / angular-material-datetimepicker

Datepicker for Angular Material, mimick's Android's date time picker
https://logbon72.github.io/angular-material-datetimepicker
MIT License
169 stars 123 forks source link

Display format #111

Closed taras-vlasenko closed 7 years ago

taras-vlasenko commented 7 years ago

Hi! I have date, stored on the server like this '2017-06-15 17:48:33.586+00' and want to display it in timepicker so when user wants to change it, he can easily do that. But my problem with format="HH:mm". When getting data from server its always set hous to 20, and minutes is correct. It could be fixed by format="YYYY-MM-HH:mm", but I'm need to show customers only time. How can I do that? Thanks

hexadecy commented 7 years ago

Look like it's working for me, it set the hours to 13, because my current time zone is -4. $scope.time = new Date('2017-06-15 17:48:33.586+00');

<md-input-container flex-gt-md="30">
  <label>Timepicker Only | 24-hour</label>
  <input mdc-datetime-picker date="false" time="true" type="text" short-time="false"
    minutes="true" min-date="minDate" format="HH:mm" ng-model="time">
</md-input-container>

Your time zone is probably +3. You should probably use https://www.w3schools.com/jsref/jsref_gettimezoneoffset.asp to know the client offset.

taras-vlasenko commented 7 years ago

@hexadecy this what i got from server. And hour always 20, no matter what is in the moment object _175

taras-vlasenko commented 7 years ago

Ok, I'm fixed this. Just need to wrap data string from server into moment object

for (let j = 0; j < data.data.rows.length; j++) {
          data.data.rows[j].timeFrom = moment(data.data.rows[j].timeFrom);
          data.data.rows[j].timeTo = moment(data.data.rows[j].timeTo);
}