util.js 1007 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const formatTime = (date) => {
  2. const year = date.getFullYear()
  3. const month = date.getMonth() + 1
  4. const day = date.getDate()
  5. const hour = date.getHours()
  6. const minute = date.getMinutes()
  7. const second = date.getSeconds()
  8. return {
  9. year:year,
  10. month:[year, month].map(formatNumber).join('-'),
  11. day:[year, month, day].map(formatNumber).join('-'),
  12. }
  13. }
  14. const formatNumber = n => {
  15. n = n.toString()
  16. return n[1] ? n : '0' + n
  17. }
  18. //删除数组的某一项
  19. const arrRemoveObj = (array, obj) => {
  20. let length = array.length;
  21. for (let i = 0; i < length; i++) {
  22. if (array[i] === obj) {
  23. if (i === 0) {
  24. array.shift();
  25. return array;
  26. } else if (i === length - 1) {
  27. array.pop();
  28. return array;
  29. } else {
  30. array.splice(i, 1);
  31. return array;
  32. }
  33. }
  34. }
  35. }
  36. module.exports = {
  37. formatTime: formatTime,
  38. arrRemoveObj:arrRemoveObj
  39. }