Javascript: Returning how many seconds to an date in a format 0000-00-00 00:00:00 -
i'm using flipclock countdown date. date i'm counting downwards in format: 0000-00-00 00:00:00.
i want how many seconds until date. can utilize in flipclock.
var clock = $('#countdown').flipclock(seconds, { clockface: 'hourlycounter', countdown: true, callbacks: { stop: function() { //callback } } });
i guess date in iso 8601 format of yyyy-mm-dd hh:mm:ss , should interpreted local time. in case, parse string, convert date object , subtract difference in milliseconds. split 1,000 difference in seconds, e.g.
// parse string in yyyy-mm-dd hh:mm:ss format // assume valid date , time in scheme timezone function parsestring(s) { var b = s.split(/\d+/); homecoming new date(b[0], --b[1], b[2], b[3], b[4], b[5]); } // difference between , provided date string // in format accepted parsestring // if d invalid string, homecoming nan // if provided date in future, returned value +ve function gettimeuntil(s) { var d = parsestring(s); homecoming d? (d - date.now())/1000|0 : nan; }
javascript date
No comments:
Post a Comment