Date showing a day off using a date filter in Angularjs

Hi, I have the following date returned by data

"2008-02-25T00:00:00Z"

When I show it with

 <span>{{meetingDate | date: 'MM/dd/yyyy'}}</span>

I get a date display

 "02/24/2008"

Basically, he shows 24 instead of 25, losing a day. Can you tell me how to fix this? Thanks

+4
source share
2 answers

try it

Working code

script

  var localDate = new Date('2008-02-25T00:00:00Z');
  var localTime = localDate.getTime();
  var localOffset = localDate.getTimezoneOffset() * 60000;
  $scope.mydate = new Date(localTime + localOffset);

HTML

{{mydate | date:'MM/dd/yyyy'}}

Output

02/25/2008
+2
source

This is a time zone issue. Your client machine must be in the time zone less than 0 (UTC time) . In general, this is not a problem since it displays the correct time based on the client machine.

0
source

Source: https://habr.com/ru/post/1536416/


All Articles