Ruby中的时区选择列表(按UTC偏移量) [英] Timezone Select List in Ruby by UTC Offset
本文介绍了Ruby中的时区选择列表(按UTC偏移量)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想按与UTC的偏移量列出一个选择,例如:
I would like to have a select listed by offset difference to UTC, like:
<select value=1>(GMT 00:00) GMT</select>
<select value=1>(GMT 00:00) Lisbon</select>
<select value=1>(GMT +00:01) Madrid</select>
就像在Rails中一样: https://signup.37signals.com/highrise/Free/signup/new
Just like in Rails: https://signup.37signals.com/highrise/Free/signup/new
我们正在使用Sinatra + Padrino.
We're using Sinatra+Padrino.
推荐答案
这是怎么回事:
ActiveSupport::TimeZone.all.inject([]) do |result, tz|
utc_offset = tz.utc_offset / 3600
result << ["(UTC #{'%.2d' % utc_offset}): #{tz.name}", utc_offset]
end
它将为options_for_select生成一个数组:
It will produce an array for options_for_select:
[["(UTC -11): International Date Line West", -11], ["(UTC -11): Midway Island", -11]...]
这篇关于Ruby中的时区选择列表(按UTC偏移量)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文