微信登录

直接用 - Date() - 时间

  1. // 时间戳转换为日期
  2. function timestampToTime(timestamp) {
  3. var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
  4. Y = date.getFullYear() + '-';
  5. M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  6. D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
  7. h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
  8. m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
  9. s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
  10. return Y + M + D + h + m + s;
  11. }
  12. //日期转换为时间戳
  13.   let timestamp = (new Date(date)).getTime() / 1000;
直接用 - Date() - 时间