zoukankan      html  css  js  c++  java
  • JS_0042:js 获取 省 市 县 经纬度 北京时间

    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
            };
    
    
    
    
        });
    琥珀君的博客
  • 相关阅读:
    Django Admin Cookbook-27如何在Django Admin后台中添加基于日期的过滤
    Django Admin Cookbook-26如何禁用Django Admin后台分页
    Django Admin Cookbook-25如何在模型列表页上显示更多行
    Django Admin Cookbook-24如何从两个不同的模型创建一个Django Admin后台页面
    Django Admin Cookbook-23如何在Django admin中添加嵌套的内联
    Django Admin Cookbook-22如何将一对一关系添加为Admin内联字段
    Django Admin Cookbook-21如何从Django Admin后台一个页面同时编辑多个模型
    个人收集的一些Django基础及实战教程
    Django Admin Cookbook-20如何删除模型的“添加”/“删除”按钮
    操作系统 RR轮转调度算法(C++实现)
  • 原文地址:https://www.cnblogs.com/eliteboy/p/14073958.html
Copyright © 2011-2022 走看看