0

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.

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');

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

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?

5
  • where do you get the date param? Commented Mar 1, 2018 at 11:43
  • when I click on calendar event, I'm send the date as parameter to the controller.js, there I'm using the filter to insert the date and time in the 2 inputs Commented Mar 1, 2018 at 11:44
  • @ElioChamy what does time input look like in code? Commented Mar 1, 2018 at 11:50
  • I just want to tell the filter to take my current timezone Commented Mar 1, 2018 at 11:55
  • The problem should not be here, but the data source. You can try it out by using new Date(), and check whether 2 hours is added to current time. Commented Mar 1, 2018 at 11:58

1 Answer 1

0

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>

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

Sign up to request clarification or add additional context in comments.

Comments