(ANGULARJS) Input[time] is showing local time when given a regular date

Mas*_*ohn 5 time input angularjs momentjs

Basically,

I received a date from my server which is, when printed out in the web console, this : Date 2016-05-04T09:00:00.000Z

Since, im using AngularJs, I did a binding using ng-model with an input time type.

现在的问题是,当我在该输入中显示日期时,我看不到: 9:00,而是5:00 (9:00 - 4:00)(我在 GMT -4 区域)

然而,日期不应该是世界时间,但正如您所见,它被解析为当地时间。有什么办法可以阻止这个吗?

Pau*_*ski 5

可以使用 ngModelOptions 定义用于读取/写入模型中的 Date 实例的时区。默认情况下,这是浏览器的时区。AngularJS API 输入[时间]

在您的情况下,以下选项应该可以解决问题。

<input type="time" ng-model-options="{ timezone: '-0400' }">
Run Code Online (Sandbox Code Playgroud)

但请注意此选项会覆盖浏览器的时区。这意味着如果用户在 UTC+2 中操作,则输入时间仍被视为 UTC-4。