Home >Web Front-end >JS Tutorial >A series of problems and solutions when using datetime in js to front-end iOS
Requirements and ideas
The key point is this End time
To be displayed Countdown time. The idea is to use the setTimeout() function.
The date type passed from the database cannot be correctly parsed inIOS
//倒计时函数 一秒钟执行一次 setInterval(daojishi,1000); //倒计时函数 用each 遍历所有需要处理的时间 function daojishi(){ $(".truetime").each(function(){ var end= $(this).html(); var end_on=formatStr(end);//解决ios手机不兼容问题 var curtime=new Date(); var endtime=new Date(end_on); var lefttime= parseInt((endtime.getTime()-curtime.getTime())/(1000)); if (lefttime>0) { var day=parseInt(lefttime/(24*60*60)); var hours=parseInt( (lefttime/(60*60))%24); var minutes=parseInt( (lefttime/(60))%60); var seconds=parseInt( (lefttime)%60); hours =checkout(hours); minutes =checkout(minutes); seconds =checkout(seconds); var title =day+' 天 '+hours+' 小時 '+minutes+' 分 '+seconds+' 秒 '; }else{ var title="时间结束" } $(this).next('span').html(title); }); };
数据库拿出来的时间是 2016-06-08 这种时间iOS并不兼容 出现未定义的时间格式 所以用下面的函数转一下 成2016/06/08
function formatStr(str) { str=str.replace(/-/g,"/"); };
var curtime=new Date();
Related articles:
JS IOS/iPhone Safari browser is not compatible with Date() in Javascript. How to solve the problem
Convert datetime type date and time into Chinese representation
Related videos:
Mobile front-end project practical video tutorial
The above is the detailed content of A series of problems and solutions when using datetime in js to front-end iOS. For more information, please follow other related articles on the PHP Chinese website!