Search code examples
angularjsangular-ngmodel

Angular ng-model issue on time input


I'm having an issue using ng-model with time input on my app. I've searched around and couldn't find any other questions regarding this but I may be mistaken.

I have time inputs with ng-model and am getting this weird "1970-01-01T09:00:00.000Z" value.

Here's a fiddle recreating my issue

<div ng-app>
    <input type="time" step="900" ng-model="startTime" />
    <input type="time" step="900" ng-model="endTime" />
    <pre>
        Start Time: {{ startTime }}
        End Time: {{ endTime }}
    </pre>
</div>

Only dependency I'm using is angualr v1.3.15


Solution

  • Looks like you're getting a javascript date, with the time portion set to whatever you selected in the input. It's showing in Zulu time (UTC), so for me if I pick 2:30 AM, it displays 1970-01-01T08:30:00.000Z. Ignore the date portion, the time portion is what I selected.

    If you want to see the selected time adjusted to your local time zone, use the date filter.

    Start Time: {{ startTime | date:"hh:mm a" }}
    End Time: {{ endTime | date:"hh:mm a" }}