ruby get Time in given timezone

前端 未结 9 1237
情书的邮戳
情书的邮戳 2020-12-28 13:17

In ruby, how can I get current time in a given timezone? I know the offset from UTC, and want to get the current time in the timezone with that offset.

9条回答
  •  自闭症患者
    2020-12-28 13:41

    gem install tzinfo
    

    Then

    require 'tzinfo'
    
    tz = TZInfo::Timezone.get('US/Pacific')
    Time.now.getlocal(tz.current_period.offset.utc_total_offset)
    

提交回复
热议问题