关于前端:vue获取日期部分

32次阅读

共计 708 个字符,预计需要花费 2 分钟才能阅读完成。

// 获取日期

function GetSysDate(timestamp) {
  var Y, m, d,  sresult;
  if (timestamp) {var date = new Date(timestamp);
  } else {var date = new Date();
  };
  Y = date.getFullYear(),
    m = date.getMonth() + 1,
    d = date.getDate();

  if (m < 10) {m = '0' + m;}
  if (d < 10) {d = '0' + d;}
  
  sresult = Y + '-' + m + '-' + d ;
  // console.log(sresult);
  return sresult;
}

// 格式化工夫戳 (返回:2017-10-21 13:18:25)

function formatTime(timestamp) {
  var Y, m, d, H, i, s, sresult;
  if (timestamp) {var date = new Date(timestamp);
  } else {var date = new Date();
  };
  Y = date.getFullYear(),
    m = date.getMonth() + 1,
    d = date.getDate(),
    H = date.getHours(),
    i = date.getMinutes(),
    s = date.getSeconds();
  if (m < 10) {m = '0' + m;}
  if (d < 10) {d = '0' + d;}
  if (H < 10) {H = '0' + H;}
  if (i < 10) {i = '0' + i;}
  if (s < 10) {s = '0' + s;}
  sresult = Y + '-' + m + '-' + d + '' + H +':'+ i +':' + s;
  // console.log(sresult);
  return sresult;
}

正文完
 0