Sachin Prasad
Sachin Prasad

Reputation: 5411

Ruby on Rails timezone

My server is in US, rails default timezone is set to 'UTC', a user from India submits the form,Will rails convert that user's time zone from India to UTC and save it in created_at column or it will save the UTC current time?

Upvotes: 1

Views: 1130

Answers (1)

vvohra87
vvohra87

Reputation: 5664

It will save the current time in UTC. Created_at and updated_at are Active Records internal timestamp columns, and as such they are never user input.

Also, basic security protocol dictates that you should never use the client's time settings, always the servers.

Rails will do one thing though - it will use the webserver's current time in UTC and store it in the database instead of the database servers current time.

By default, times are stored in UTC + offset format. When you specify the default timezone as lets say "Mumbai" it will return the datetime objects converted for that timezone.

You can also do:

Time.zone.parse(@post.created_at.zone)

Upvotes: 2

Related Questions