Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ruby DateTime オブジェクトのタイムゾーンを出力しようとしています:
DateTime.parse('2012/05/23').strftime('%Z')
これは を出力します"+00:00"。ドキュメントによると、 を返す必要がありGMTます。
"+00:00"
GMT
私は何か間違ったことをしていますか、それともバグを見つけましたか?
このDateTimeクラスは、ゾーン名としてゾーン データをサポートしていないようです。ただし、Timeクラスはこれを正しく行います。したがって、次のいずれかを行います。
DateTime
Time
require 'date' require 'time' Time.parse('...').strftime('%Z')
または、すでにデータがDateTimeフォーマットされている場合は、次のようにします。
Time.parse(DateTime.parse('...').to_s).strftime('%Z')