Ruby on Rails Sunday, July 27, 2014

On 27 July 2014 13:13, Ronald Fischer <lists@ruby-forum.com> wrote:
> I store my dates in the database as 'datetime', and I use i.e.
> DateTime.now for getting the current date and time and doing time
> arithmetic. I have set neither config.time_zone nor a default locale in
> config/application.rb
>
> When outputting such a time value, I just convert it to string, i.e.
> "#{my_timestamp}", which gives me the UTC time like this:
>
> "2014-07-27 11:41:50 UTC"
>
> This is exactly what I want to have. There are, however, cases (for
> debugging output), where I would like to print for conveniece the local
> time for such a timestamp, in addition to the UTC time. "local time"
> means in this case the time as defined as local on the host where the
> Rails server (WEBrick) is running. Note that the shell, from where I
> start the server, does NOT have the environment variable TZ set.
>
> Now my question:
>
> From the viewpoint of Rails, does the term "local time" make any sense
> (given that I have neither TZ nor config.time_zone)?
>
> If yes, how can I format the DateTime object in a way that it shows the
> time in local time?
>
> If not, what would be the best approach in this case?

Not addressing the 'local time' issue, but if you know what time zone
you want it in then you can use, for example
my_timestamp.in_time_zone("London")

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLu9kUjSWdJORimFCCboJ3qEdxnzMz0uA_Hknq_c1zbeiA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment