Himmators
Himmators

Reputation: 15006

Total number of days in angular?

I'm using angular datefilter to output a countdown. I do it like this:

<p class="clock">{{timeleft| date:'dd'}}<span>:</span>{{timeleft | date:'HH'}}<span>:</span>{{timeleft | date:'mm'}}<span>:</span>{{timeleft | date:'ss'}}</p>

$scope.timeleft contains a value that is calculated from taking launch-date minus current date.

Currently, there is more than one month left before the countdown reaches 0. I would like to show the number of days in total, that is, more than the number of days in the current month.

Upvotes: 0

Views: 1336

Answers (1)

Matt Way
Matt Way

Reputation: 33161

This is more a question about calculating date differences, than something to do with angular. I have created a simple fiddle for you here: http://jsfiddle.net/IgorMinar/ADukg/

Basically you can calculate a date difference between two dates like this:

var dstring = '2014-03-09'; // date to check against the current date
var oneDay = 24*60*60*1000;
var diff =  Math.floor(( Date.parse(dstring) - new Date() ) / oneDay);

Then just plug the value into angular any way you like.

Upvotes: 1

Related Questions