dayjs 的用法 plugin isSameOrBefore

doc: https://day.js.org/docs/en/query/is-same-or-before
1. 前面要加 import
2. dayjs 要 dayjs.extend(isSameOrBefore)
3. 直接用 tz() 就好,裡面不用加 ('Asia/Taipei') 我沒聽懂原因。
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'
dayjs.extend(isSameOrBefore)
const todayDate = dayjs().tz()
dayjs(initialDate) .tz() .isSameOrBefore(todayDate)
Subscribe to my newsletter
Read articles from Sun Pochin directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Sun Pochin
Sun Pochin
I was the main web front-end engineer responsible for developing and maintaining the customer-facing platform for WisdomHall (品學堂) in 2024 Q3 Q4, code reviewed by CTO and a senior engineer. http://learning.wisdomhall.com.tw has total active 257k users, according to their Facebook post: https://www.facebook.com/share/p/1MnjbwZxCV/ My tech stack includes JavaScript, Vue 2, Nuxt 2, git, and Docker.