//获取时间
var t = null;
t = setTimeout(time, 1000); //開始运行
function time() {
    clearTimeout(t); //清除定时器
    dt = new Date();
    var y = dt.getFullYear();
    var mt = Appendzero(dt.getMonth() + 1);
    var day = Appendzero(dt.getDate());
    var h = Appendzero(dt.getHours()); //获取时
    var m = Appendzero(dt.getMinutes()); //获取分
    var s = Appendzero(dt.getSeconds()); //获取秒
    document.querySelector(".showTime").innerHTML =

        y +
        "-" +
        mt +
        "-" +
        day +
        " " +
        h +
        ":" +
        m +
        ":" +
        s;
    t = setTimeout(time, 1000); //设定定时器，循环运行
}


//获取天气
$(function() {
    $.ajax({
        url: "https://api.asilu.com/weather/",
        type: 'GET',
        dataType: 'jsonp',
        data: {
            "key": "adfdb863ddb1101bb6b40c0700d6203b",
        },
        success: function(html) {
            var str = "";
            str += "<span>" + html.city + "</span>";
            // str += "<span>" + html.weather[0].date + "</span>";
            str += "<span>" + html.weather[0].weather + "</span>";
            str += "<span>" + html.weather[0].temp + "</span>";
            str += "<span>" + html.weather[0].wind + "</span>";
            str += "</tr>";
            $(".weather").html(str)
        }
    });
})


/* 个位补零*/
function Appendzero(obj) {
    if (obj < 10) return "0" + obj;
    else return obj;
}

function add0(m) { return m < 10 ? '0' + m : m }


//时间戳转化成时间格式
function getFormatDate(timestamp) {
    //timestamp是整数，否则要parseInt转换,不会出现少个0的情况
    var time = new Date(timestamp);
    var year = time.getFullYear();
    var month = time.getMonth() + 1;
    var date = time.getDate();
    var hours = time.getHours();
    var minutes = time.getMinutes();
    var seconds = time.getSeconds();
    return year + '-' + add0(month) + '-' + add0(date) + ' ' + add0(hours) + ':' + add0(minutes) + ':' + add0(seconds);
}


/* 毫秒转化*/
function test(time_distance) {
    // 天时分秒换算 
    var int_day = Math.floor(time_distance / 86400)
    time_distance = time_distance - int_day * 86400;

    var int_hour = Math.floor(time_distance / 3600)
    time_distance = time_distance - int_hour * 3600;

    var int_minute = Math.floor(time_distance / 60)
    time_distance = time_distance - int_minute * 60;

    var int_second = Math.floor(time_distance)
    // 时分秒为单数时、前面加零 
    if (int_day < 10) {
        int_day = "0" + int_day;
    }
    if (int_hour < 10) {
        int_hour = "0" + int_hour;
    }
    if (int_minute < 10) {
        int_minute = "0" + int_minute;
    }
    if (int_second < 10) {
        int_second = "0" + int_second;
    }
    return int_day + '天';
}


//alert(test(3000000));
// console.log(test);