time.js 617 B

1234567891011121314
  1. // 时间格式化
  2. export const getTime = () => {
  3. var date = new Date(),
  4. year = date.getFullYear(),
  5. month = date.getMonth() + 1,
  6. day = date.getDate(),
  7. hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
  8. minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
  9. second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  10. month >= 1 && month <= 9 ? (month = "0" + month) : "";
  11. day >= 0 && day <= 9 ? (day = "0" + day) : "";
  12. var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
  13. return timer;
  14. }