javascript - Getting the time remaining until a date -


i'm trying generate string says how long left deadline can't figure out how work out amount of time because of how inconsistent calender is.

i want output string such "1 month, 6 days , 10 hours remaining".

here have:

this.getremainingtimestring = function() { if(this.ispastdeadline())     return 'past deadline';  var str = ''; var diffms = - this.enddate - (new date()).gettime(); var diff = new date(diffms); var defdate = new date(0);  var years = diff.getfullyear() - defdate.getfullyear(); var months = diff.getmonth(); var days = diff.getdate();  if(years > 0) {     str += years + ' year' + (years != 1 ? 's' : '') + ' '; }  if(months != 0) {     str += months + ' month' + (months != 1 ? 's' : ''); }  if(days != 1) {     str += days + ' day' + (days != 1 ? 's' : ''); }       return str; }; 


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -