date.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * @Author: NMTuan
  3. * @Email: NMTuan@qq.com
  4. * @Date: 2024-02-19 22:13:33
  5. * @LastEditTime: 2024-02-19 23:06:51
  6. * @LastEditors: NMTuan
  7. * @Description:
  8. * @FilePath: /timeNow/stores/date.ts
  9. */
  10. import { defineStore } from 'pinia'
  11. export const useDateStore = defineStore('date', () => {
  12. const year = ref('1970')
  13. const month = ref('01')
  14. const date = ref('01')
  15. const hour = ref('00')
  16. const minute = ref('00')
  17. const second = ref('00')
  18. const millisecond = ref(0)
  19. const day = ref(1)
  20. const getNow = () => {
  21. const today = new Date()
  22. year.value = today.getFullYear().toString()
  23. month.value = (today.getMonth() + 1).toString().padStart(2, '0')
  24. date.value = today.getDate().toString().padStart(2, '0')
  25. hour.value = today.getHours().toString().padStart(2, '0')
  26. minute.value = today.getMinutes().toString().padStart(2, '0')
  27. second.value = today.getSeconds().toString().padStart(2, '0')
  28. millisecond.value = today.getMilliseconds()
  29. day.value = today.getDay()
  30. }
  31. return {
  32. year,
  33. month,
  34. date,
  35. hour,
  36. minute,
  37. second,
  38. millisecond,
  39. day,
  40. getNow
  41. }
  42. })