Created
October 24, 2011 22:35
-
-
Save nonrational/1310578 to your computer and use it in GitHub Desktop.
Days, Hours, Minutes, Seconds until Midnight at YYYY-MM-DD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function timeRemaining(yr, m, d) { | |
function pad(i) { | |
return (i < 10) ? "0" + i : "" + i; | |
} | |
var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
var theyear = yr, themonth = m, theday = d, today = new Date(); | |
var todayy = today.getYear(); | |
if (todayy < 1000){ | |
todayy += 1900 | |
} | |
var todaym = today.getMonth(), todayd = today.getDate(), todayh = today.getHours(), todaymin = today.getMinutes(), todaysec = today.getSeconds(); | |
var todaystring = montharray[todaym] + " " + todayd + ", " + todayy + " " + todayh + ":" + todaymin + ":" + todaysec; | |
var futurestring = montharray[m - 1] + " " + d + ", " + yr; | |
dd = Date.parse(futurestring) - Date.parse(todaystring); | |
dday = Math.floor(dd / (60 * 60 * 1000 * 24) * 1); | |
dhour = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1); | |
dmin = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1); | |
dsec = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1); | |
return pad(dday) + ":" + pad(dhour) + ":" + pad(dmin) + ":" + pad(dsec); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment