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

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