我有用户的时区,假设为
timeZone: 'America/New_York'
我想根据用户的时区在午夜执行一些任务。如何检查该时区是否已经到达午夜?
我有用户的时区,假设为
timeZone: 'America/New_York'
我想根据用户的时区在午夜执行一些任务。如何检查该时区是否已经到达午夜?
在某个特定时区的昨晚午夜:
new Date(new Date().toLocaleDateString('en-US', { timeZone: 'America/New_York', timeZoneName: 'short' } ))
获取指定时区当天午夜的数据库友好型UTC时间
new Date(new Date().toLocaleDateString('en-US', { timeZone: 'America/New_York', timeZoneName: 'short' } )).toISOString()
new Date()
是当前时间(无论时区如何-时间对象)
.toLocaleDateString('en-US', { timeZone: 'America/New_York', timeZoneName: 'short' } )
在指定的时区中显示当前日期(没有时间,因此是午夜),并带有时区引用的字符串
new Date(<above midnight time in zone>)
解析该时区的午夜时间,并显示相应的当前时区时间(时间对象)
.toISOString()
在UTC参考下显示以上内容(ISO日期时间字符串)