1,
// 获取省市县位置 $(function () { var latlon = null; //ajax获取用户所在经纬度 $.ajax({ url: "http://api.map.baidu.com/location/ip?ak=2TGbi6zzFm5rjYKqPPomh9GBwcgLW5sS&coor=bd09ll", type: "POST", dataType: "jsonp", success: function (data) { // 获取经纬度 22.54605355,114.02597366 latlon = data.content.point.y + "," + data.content.point.x; console.log(latlon); //ajax根据经纬度获取省市区 $.ajax({ type: "POST", dataType: "jsonp", url: ‘http://api.map.baidu.com/geocoder/v2/?ak=2TGbi6zzFm5rjYKqPPomh9GBwcgLW5sS&callback=renderReverse&location=‘ + latlon + ‘&output=json&pois=0‘, success: function (json) { if (json.status == 0) { // 获取省市区 广东省 深圳市 福田区 console.log(json.result.addressComponent.province+‘ ‘+json.result.addressComponent.city+‘ ‘+json.result.addressComponent.district); } } }); } }); // 获取本机的北京时间 // Wed Dec 02 2020 11:39:04 GMT+0800 (中国标准时间) var ti = new Date($.ajax({async: false}).getResponseHeader("Date")); console.log(ti); // 2020-12-2 11:39:04 var datetime = ti.toLocaleString(‘chinese‘, { hour12: false }).split(‘/‘).join(‘-‘); console.log(datetime); // 2020-12-2 11:39:04 var datetime1 = ti.getFullYear() + ‘-‘ + (ti.getMonth() + 1) + ‘-‘ + ti.getDate() + ‘ ‘ + ti.getHours() + ‘:‘ + ti.getMinutes() + ‘:‘ + ti.getSeconds(); console.log(datetime1); // 2020-12-2 var datetime2 = ti.getFullYear() + ‘-‘ + (ti.getMonth() + 1) + ‘-‘ + ti.getDate(); console.log(datetime2); // 腾讯获取当前时间API http://vv.video.qq.com/checktime?otype=json // 苏宁易购获取当前时间API https://f.m.suning.com/api/ct.do // 淘宝获取当前时间API http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp // 京东获取当前时间API https://a.jd.com//ajax/queryServerData.html // 获取网络的北京时间 $.ajax({ type: "POST", dataType: "jsonp", url: ‘http://vv.video.qq.com/checktime?otype=json‘, success: function (json) { // {s: "o", t: 1606890761, ip: "119.136.32.154", pos: "---", rand: "q1KyWQ2XJEgfl7j2K7Vfrg=="} console.log(json); // 获取当前北京时间戳 1606890339 // console.log(json.t); var ti = json.t * 1000; // 2020-12-02 console.log(getYMDHMS (ti)); // 获取当前IP 119.136.32.154 console.log(json.ip); // 获取唯一的随机数 ffe7-72lffnTymU9am1VoA== console.log(json.rand); // if (json.status == 0) { // } } }); // 获取本机时间戳 // console.log(Math.round(new Date() / 1000)); // 时间戳转换yyyy-mm-dd function getYMDHMS (timestamp) { let time = new Date(timestamp) let year = time.getFullYear() let month = time.getMonth() + 1 let date = time.getDate() let hours = time.getHours() let minute = time.getMinutes() let second = time.getSeconds() if (month < 10) { month = ‘0‘ + month } if (date < 10) { date = ‘0‘ + date } if (hours < 10) { hours = ‘0‘ + hours } if (minute < 10) { minute = ‘0‘ + minute } if (second < 10) { second = ‘0‘ + second } // return year + ‘-‘ + month + ‘-‘ + date + ‘ ‘ + hours + ‘:‘ + minute + ‘:‘ + second return year + ‘-‘ + month + ‘-‘ + date }; });