countdown - javascript: convert seconds to months -


i using following script countdown.

function startcountdown() {     var countdowndate = new date("9/13/2013 12:00 am");     var currentdate = new date();     var datedifference = new date(countdowndate - currentdate);     var seconds = datedifference.valueof() / 1000;     countback(seconds); }  function countback(seconds) {     var displayformat = "days days , hours hours";     displayformat = displayformat.replace("days", (math.floor(seconds/86400)) % 100000);     displayformat = displayformat.replace("hours", (math.floor(seconds/3600)) % 24);     $('span.countdown').html(displayformat); }  startcountdown(); 

how can show months left too? (i want like: 3 months, 29 days , 3 hours)

thank you.

use simple nice function. check out live demo:

var cc = new date("9/13/2012 12:00 am"),     c = new date();  function timedifference(d, dd) {     var hour = 60 * 60 * 1000,         day = hour * 24,         month = day * 30,         ms = math.abs(d - dd),         months = parseint(ms / month, 10);          ms = ms - months * month;         var days = parseint(ms / day, 10);      ms -= days * day;     var hours = parseint(ms / hour, 10);        ms -= hours * hour;      return [         months + " months",         days + " days",         hours + " hours"     ].join(", "); };  document.body.innerhtml += timedifference(cc, c) + "<br />"; 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -