Ruby DateTime human timezone output

I am trying to infer the time zone of a Ruby DateTime object:

DateTime.parse('2012/05/23').strftime('%Z') 

This displays "+00:00" . According to the documentation, he should return GMT .

Am I doing something wrong, or have I found a mistake?

+4
source share
1 answer

The DateTime class does not seem to support zone data as zone names. The Time class, however, does it right. So or do this:

 require 'date' require 'time' Time.parse('...').strftime('%Z') 

Or, if you already have data in DateTime format, then:

 Time.parse(DateTime.parse('...').to_s).strftime('%Z') 
+1
source

Source: https://habr.com/ru/post/1414264/


All Articles