date.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * @Author: NMTuan
  3. * @Email: NMTuan@qq.com
  4. * @Date: 2024-02-19 22:13:33
  5. * @LastEditTime: 2024-02-22 13:17:11
  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 settingStore = useSettingStore()
  13. const year = ref('1970')
  14. const month = ref('01')
  15. const date = ref('01')
  16. const hour = ref('00')
  17. const hour12 = ref('00')
  18. const minute = ref('00')
  19. const second = ref('00')
  20. const millisecond = ref(0)
  21. const day = ref(1)
  22. const getNow = () => {
  23. const today = new Date()
  24. year.value = today.getFullYear().toString()
  25. month.value = (today.getMonth() + 1).toString().padStart(2, '0')
  26. date.value = today.getDate().toString().padStart(2, '0')
  27. hour.value = today.getHours().toString().padStart(2, '0')
  28. let h = today.getHours()
  29. if (!settingStore.hour24 && h > 12) {
  30. h = h % 12
  31. }
  32. hour12.value = h.toString().padStart(2, '0')
  33. minute.value = today.getMinutes().toString().padStart(2, '0')
  34. second.value = today.getSeconds().toString().padStart(2, '0')
  35. millisecond.value = today.getMilliseconds()
  36. day.value = today.getDay()
  37. }
  38. return {
  39. year,
  40. month,
  41. date,
  42. hour,
  43. hour12,
  44. minute,
  45. second,
  46. millisecond,
  47. day,
  48. getNow
  49. }
  50. })