javascripts/jquery countdown giving wrong hours on mobile -
i'm counting down eclipse using jquery countdown.js. counts correctly on desktop. on mobile (android), countdown 1 hour ahead. on other people's mobile, countdown shows 0 hours. doing wrong? not accounting timezone? should matter? countdown eclipse (less 4 hours now), use quickly!
var date = new date("2017-08-21t13:18:00"); //1:18 p.m. est $("#dayelem") .countdown(date, function(event) { if (event.strftime('%-d') < 10) { $(this).text('0' + event.strftime('%-d') ); } else { $(this).text( event.strftime('%-d') ); } }); $("#hourelem") .countdown(date, function(event) { if (event.strftime('%-h') < 10) { $(this).text('0' + event.strftime('%-h') ); } else { $(this).text( event.strftime('%-h') ); } }); $("#minuteelem") .countdown(date, function(event) { if (event.strftime('%-m') < 10) { $(this).text('0' + event.strftime('%-m') ); } else { $(this).text( event.strftime('%-m') ); } }); $("#secondelem") .countdown(date, function(event) { if (event.strftime('%-s') < 10) { $(this).text('0' + event.strftime('%-s') ); } else { $(this).text( event.strftime('%-s') ); } });
i think assumption correct. have account current timezone. easiest way accomplish use moment.js (https://momentjs.com/) , modify code this:
var date = moment.utc('2017-08-21t17:18:00').todate(); $("#dayelem") .countdown(date, function (event) { if (event.strftime('%-d') < 10) { $(this).text('0' + event.strftime('%-d') ); } else { $(this).text( event.strftime('%-d') ); } }); $("#hourelem") .countdown(date, function (event) { if (event.strftime('%-h') < 10) { $(this).text('0' + event.strftime('%-h') ); } else { $(this).text( event.strftime('%-h') ); } }); $("#minuteelem") .countdown(date, function (event) { if (event.strftime('%-m') < 10) { $(this).text('0' + event.strftime('%-m') ); } else { $(this).text( event.strftime('%-m') ); } }); $("#secondelem") .countdown(date, function (event) { if (event.strftime('%-s') < 10) { $(this).text('0' + event.strftime('%-s') ); } else { $(this).text( event.strftime('%-s') ); } });
also note specified time in utc instead of est.
when running code in timezone, cet, got zeroes. when using code above got 3 hours , 10 minutes @ time of posting this.
wiki
Comments
Post a Comment