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?

I've already looked at the DateTime member functions to see, whether
there is something like "getlocal" or "localtime", but there doesn't
seem to be one.  to_formatted_s looked promising, but I didn't find
anysthing in the possible time format specifiers which would help me
here.

Ronald

-- 
Posted via http://www.ruby-forum.com/.

-- 
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+unsubscr...@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/76141a76b98eea31545c578c11ff371b%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to