简体   繁体   中英

How to add icon when last reading date is more than 24hours old?

so in my html I have this:

{{hsParametersLastRead.readingDate | date:'medium'}}

and I have this in the controller:

$http.get(hsParametersLastReadEndpoint).success(function (hsParametersLastRead) {
                $scope.hsParametersLastRead = hsParametersLastRead;
                console.log(moment());
            });

I have this moment thing that I don't really know how to use.

What I want: to be able to make an icon visible if the hsParametersLastRead.readingDate is older than 24 hours. Can I somehow compare it with the 'moment' object and check if 24 hours has passed since?

You could do something like this:

var now = moment();
var difference = moment($scope.hsParametersLastRead.readingDate).diff(now, 'hours');

Difference should be the number of hours between now and your hsParametersLastRead property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM