【发布时间】:2016-06-09 15:45:45
【问题描述】:
我正在Angular 中编写一个应用程序,并且我正在使用Angular UI 连同它。我有一个看起来像这样的日期选择器:
<input type="text"
ng-required="true"
name="targetDate"
uib-datepicker-popup="MMMM yyyy"
min-mode="'month'"
datepicker-mode="'month'"
is-open="opened"
ng-click="openCalendar()"
close-on-date-selection="true"
show-button-bar="false"
min-date="today"
ng-model="targetDate" />
问题是,例如,当我选择 2016 年 7 月时,我的 targetDate 模型中的值是“2016-06-30T21:00:00.000Z”,正好是 2016 年 7 月之前的 3 小时。我认为这与我的本地时间和 UTC 时间有关,因为我住在一个本地时间为 +2 小时 UTC 的地区,但我不知道为什么会发生这种情况以及如何解决它。有什么想法吗?
【问题讨论】:
-
您需要使用 MomentJs 库 momentjs.com/docs 将 UTC 转换为本地时间。如果您已经知道 momentjs,请阅读 abt for Quick digitoffee.com/programming/get-local-time-utc-using-moment-js/…
-
momentjs.com/docs 从头开始使用
-
这个问题之前已经提到过:stackoverflow.com/questions/22623872/…
-
对我不起作用 :)
标签: javascript angularjs datepicker angular-ui