formateTime.js 838 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. function setNowTimes() {
  2. let myDate = new Date();
  3. // console.log(myDate)
  4. let wk = myDate.getDay();
  5. let yy = String(myDate.getFullYear());
  6. let mm = myDate.getMonth() + 1;
  7. let dd = String(
  8. myDate.getDate() < 10 ? "0" + myDate.getDate() : myDate.getDate()
  9. );
  10. let hou = String(
  11. myDate.getHours() < 10 ? "0" + myDate.getHours() : myDate.getHours()
  12. );
  13. let min = String(
  14. myDate.getMinutes() < 10 ?
  15. "0" + myDate.getMinutes() :
  16. myDate.getMinutes()
  17. );
  18. let sec = String(
  19. myDate.getSeconds() < 10 ?
  20. "0" + myDate.getSeconds() :
  21. myDate.getSeconds()
  22. );
  23. let weeks = [
  24. "星期日",
  25. "星期一",
  26. "星期二",
  27. "星期三",
  28. "星期四",
  29. "星期五",
  30. "星期六"
  31. ];
  32. let week = weeks[wk];
  33. return yy + "年" + mm + "月" + dd + "日" + hou + ":" + min + ":" + sec;
  34. }
  35. module.exports = {
  36. setNowTimes: setNowTimes
  37. }