首页 > 其他 > 详细

时间日期格式化并进制转化

时间:2019-11-27 11:51:28      阅读:65      评论:0      收藏:0      [点我收藏+]
function createGuid() {
    // 进制转换  x=10/16/2/8
    var hexadecimal = function(num, x, y) {
      if (y != undefined) {
        return parseInt(num.toString(), y).toString(x);
      } else {
        return parseInt(num.toString()).toString(x);
      }
    };
    // 补零
    var addZero = function(num) {
      if (Number(num).toString() != ‘NaN‘ && num >= 0 && num < 10) {
        return ‘0‘ + Math.floor(num);
      } else {
        return num.toString();
      }
    };
    // 年月日
    var getGUIDDate = function(date) {
      return (
        date.getFullYear() +
        ‘-‘ +
        addZero(date.getMonth() + 1) +
        ‘-‘ +
        addZero(date.getDay())
      );
    };
    // 时分秒
    var getGUIDTime = function(date) {
      return (
        addZero(date.getHours()) +
        ‘:‘ +
        addZero(date.getMinutes()) +
        ‘:‘ +
        addZero(date.getSeconds())
      );
    };
    var date = new Date();
    var guidStr = hexadecimal(getGUIDDate(date), 16);
    return guidStr;
  }

 

时间日期格式化并进制转化

原文:https://www.cnblogs.com/jrg-Archer/p/11940696.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!