zoukankan      html  css  js  c++  java
  • 【通用】将指定时间转换为北京时间

    function formDate(dateForm) {
        if (dateForm === "") {  //解决deteForm为空传1970-01-01 00:00:00
            return "";
        }else{
            var dateee = new Date(dateForm).toJSON();
            var date = new Date(+new Date(dateee)+ 8 * 3600 * 1000).toISOString().replace(/T/g,' ').replace(/.[d]{3}Z/,'');
            return date;
        }
    }
    
    function getBeijingTime(t) {
        var d = new Date(); // 获得当前运行环境时间
        var currentDate = new Date(t);
        var tmpHours = currentDate.getHours();
    
        var time_zone = -d.getTimezoneOffset() / 60; // 算得时区
        if (time_zone < 0) {
            time_zone = Math.abs(time_zone) + 8; // 算得小时偏移
            currentDate.setHours(tmpHours + time_zone);
        } else {
            time_zone -= 8; // 算得小时偏移
            currentDate.setHours(tmpHours - time_zone);
        }
        return currentDate;
    }
    
    function  getBeijingTimeStamp(currentDate){
        const y = currentDate.getFullYear();   //当前客户端对应的北京时间的年
          const m = currentDate.getMonth();   //北京时间的月
          const d = currentDate.getDate();
          const h = currentDate.getHours();
         const mm = currentDate.getMinutes();
         const ss = currentDate.getSeconds();
         // Date.UTC() 方法接受的参数同日期构造函数接受最多参数时一样,返回从1970-1-1 00:00:00 UTC到指定日期的的毫秒数。
          const timeObj = Date.UTC(y, m, d, h, mm, ss, 0) - (8 * 60 * 60 * 1000);
          return timeObj;
    }
    var today = getBeijingTime(new Date().getTime()) // 输入时间戳,然后获取到北京时间对象
    var stick = getBeijingTimeStamp(today) // 输入时间对象,然后获取到 北京时间戳
    formDate(stick)
  • 相关阅读:
    HUE配置HBase
    HUE配置HIVE
    HUE配置hadoop
    HUE的安装
    CM (Cloudera Manager) 的安装,便于CDH的离线部署
    MapReduce -- 最短路径
    Mapreduce -- PageRank
    CentOS 建立本地yum源服务器
    js移动设备手机跳转地址代码
    离线存储
  • 原文地址:https://www.cnblogs.com/mailyuan/p/15305510.html
Copyright © 2011-2022 走看看