AngularJs过滤日期增加2小时 [英] AngularJs filter date adding 2 hours

查看:31
本文介绍了AngularJs过滤日期增加2小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个预订日历,可以单击日期和时间,因此我打开了一个引导程序模版,其中有一个日期输入和一个时间输入.

I have a reservation calendar, where I can click on day and time, so I open a bootstrap modal where there is a date input and a time input.

我正在使用带有"date"参数的模态负载:

I'm using on the modal load with "date" parameter:

 $scope.calendarChosenDay = $filter('date')(new Date(date), 'yyyy-MM-dd');
 $scope.calendarChosenTime = $filter('date')(new Date(date), 'HH:mm');

模态打开时,日期是正确的,但由于我猜是时区,所以时间增加了2个小时.

When the modal opens, the date is correct, but the time is adding 2 hours because of timezone i guess.

我应该添加到过滤器中的什么内容,以使当前时区像现在的1:40 pm一样,给我3:40 pm,我希望它是1:40.有帮助吗?

What should I add to the filter, to take the current timezone like now its 1:40 pm it s giving me 3:40 pm, I want it to be 1:40. Any help?

推荐答案

代码正确显示了当前时区中的日期:

The code correctly shows dates in the current timezone:

angular.module("app",[])
.run(function($filter){
  var s = $filter('date')(new Date(), 'HH:mm');
  console.log(s);
})

<script src="//unpkg.com/angular/angular.js"></script>
<body ng-app="app"></body>

问题不在于代码,而在于 date 变量的原始来源.

The problem is not with the code but the original source of the date variable.

这篇关于AngularJs过滤日期增加2小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆