Home > Web Front-end > JS Tutorial > A series of problems and solutions when using datetime in js to front-end iOS

A series of problems and solutions when using datetime in js to front-end iOS

php是最好的语言
Release: 2018-07-28 13:59:59
Original
1942 people have browsed it

Requirements and ideas

A series of problems and solutions when using datetime in js to front-end iOS

The key point is this End time To be displayed Countdown time. The idea is to use the setTimeout() function.

Problems encountered

The date type passed from the database cannot be correctly parsed inIOS

Code

//倒计时函数  一秒钟执行一次
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);
    });
};
Copy after login

Problems

数据库拿出来的时间是  2016-06-08  这种时间iOS并不兼容 出现未定义的时间格式 所以用下面的函数转一下  成2016/06/08
Copy after login

Solution

function formatStr(str) {
    str=str.replace(/-/g,"/");
};
Copy after login

Thinking about the program

var curtime=new Date();
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template