Ruby - 有没有办法获取特定未来时间的时间戳,但它取决于时区
Ruby - Is there a way to get the timestamp for a specific future time but have that be dependent on timezone
我有一个电子邮件系统。我想在当地时间早上 8 点向人们发送电子邮件。如果我的时区格式为:“America/New_York”,我怎样才能获得该时区的下一个 8AM 实例的时间对象?
我假设您有一个 User
模型并且每个用户都将其时区存储在属性 timezone
和 timezone #=> 'America/New_York'
.
中
然后您可以将如下方法添加到您的 User
模型中:
def next_time_it_is_8am_in_this_users_timezone_in_utc
time = ActiveSupport::TimeZone[timezone].now.change(hour: 8)
time = time + 1.day if time.past?
time.utc
end
我有一个电子邮件系统。我想在当地时间早上 8 点向人们发送电子邮件。如果我的时区格式为:“America/New_York”,我怎样才能获得该时区的下一个 8AM 实例的时间对象?
我假设您有一个 User
模型并且每个用户都将其时区存储在属性 timezone
和 timezone #=> 'America/New_York'
.
然后您可以将如下方法添加到您的 User
模型中:
def next_time_it_is_8am_in_this_users_timezone_in_utc
time = ActiveSupport::TimeZone[timezone].now.change(hour: 8)
time = time + 1.day if time.past?
time.utc
end