Hi all,

Im having an issue regarding saving time in db.

First my requirement is -

1.I save current date and time in "Publish on" field.

2. Now this should be changed to date and time based on user's location
which will be stored.

For example, if user is in EST, The publish on date should be in EST
format.

I used this,

Time.parse(publish_on.to_s).in_time_zone('EST')
Time.parse(publish_on.to_s).in_time_zone('MST')

when i put the string, it shows time based on EST or MST.

But while storing the date, it stores in default time zone.

Can anyone suggest me in this on how to save different time zone in
rails?

--
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Adam Ms. at Dec 28, 2011 at 4:01 pm
    Always save time in UTC.

    You can add an additional string field if necessary that contains a
    string of the time zone it came from.

    --
    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 post to this group, send email to [email protected].
    To unsubscribe from this group, send email to [email protected].
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Felipe Fontoura at Dec 30, 2011 at 3:44 pm
    Hello!

    It's a normal pattern in rails. It always save the timestamp in GMT
    timezone, and you never change it!

    I suggest to you create a helper to calculate the time based in the user's
    timezone.

    []'s

    ---
    Felipe Fontoura
    Eng. de Computação
    http://www.felipefontoura.com


    2011/12/28 angel david <[email protected]>
    Hi all,

    Im having an issue regarding saving time in db.

    First my requirement is -

    1.I save current date and time in "Publish on" field.

    2. Now this should be changed to date and time based on user's location
    which will be stored.

    For example, if user is in EST, The publish on date should be in EST
    format.

    I used this,

    Time.parse(publish_on.to_s).in_time_zone('EST')
    Time.parse(publish_on.to_s).in_time_zone('MST')

    when i put the string, it shows time based on EST or MST.

    But while storing the date, it stores in default time zone.

    Can anyone suggest me in this on how to save different time zone in
    rails?

    --
    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 post to this group, send email to [email protected].
    To unsubscribe from this group, send email to
    [email protected].
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to [email protected].
    To unsubscribe from this group, send email to [email protected].
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 28, '11 at 9:28a
activeDec 30, '11 at 3:44p
posts3
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Adam Ms.: 2 posts Felipe Fontoura: 1 post

People

Translate

site design / logo © 2023 Grokbase