给定一个(UTC)DateTime
对象,我怎样才能在柏林相应的时间,在CET或CEST,根据日期?
对于所需的“转换”功能,例如:
convert(DateTime.new(2018, 07))
=> Sun, 01 Jul 2018 02:00:00 +0200
convert(DateTime.new(2018, 12))
=> Sat, 01 Dec 2018 01:00:00 +0100
尝试这个
require 'tzinfo'
timezone = TZInfo::Timezone.get('Europe/Berlin')
local_time = timezone.utc_to_local(utc_time)
即使工作没有Rails的。