Tim Koelkebeck
Tim Koelkebeck

Reputation: 815

how to display timestamp without timezone

@object.updated_at.localtime displays "2015-04-20 14:39:27 -0700". I don't want to display the -0700, is there a method that will strip out the timezone for display purposes?

Upvotes: 4

Views: 10246

Answers (3)

mrstif
mrstif

Reputation: 2946

If you plan to use that format across your app, you might as well create a new time format:

# config/initializers/time_formats.rb
Time::DATE_FORMATS[:no_timezone] = "%Y-%m-%d %H:%M:%S"

Then just use it like this:

Time.now.to_s(:no_timezone)

Upvotes: 6

joseramonc
joseramonc

Reputation: 1931

You should use I18n.l and define a format in. your language.yml

I18n.l @object.updated_at, format: :my_format

en.yml

en:
  time:
    formats:
      myformat: "%Y-%m-%d %H:%M"

Upvotes: 3

makhan
makhan

Reputation: 4009

@object.updated_at.localtime.strftime '%Y-%m-%d %H:%M:%S'

Upvotes: 10

Related Questions