开发者

Determining the date in a timezone that is different than Time.zone

开发者 https://www.devze.com 2022-12-25 04:35 出处:网络
My Rails application makes use of Time.zone so that each user can set their own timezone and see timestamps in the correct zone. However, I would like to have some content that is only available for o

My Rails application makes use of Time.zone so that each user can set their own timezone and see timestamps in the correct zone. However, I would like to have some content that is only available for one day, but for that one day to be the same 24 hours for all users.

In order to do that, I was going to use if Time.zone.today == Time.zone.local(year, mon开发者_JAVA百科th, day).to_date, but obviously that will just check the 24 hours that the day is the same in the current (ie. users') timezone.

Is there any way to do this without having to change Time.zone to the timezone I want to use first?


Just don't use the Time.zone, use server time. There isn't any need to get into what time the user thinks it is if you only want it to be the same 24 hours for everybody.

if Time.today == Time.local(year, month, day).to_date
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号