Timezone or Time conflict

I followed the instructions to setup the timezone on the server from the Getting Started with Linode guide.

I deployed a Rails App but I'm getting the times wrong on the created_at columns.

I go to rails console production and ran Time.now and I get the correct time.

I logged in to MySQL and ran SELECT NOW(); and I get the correct time.

But when a new record is created into the database I get that it's about 5am when it's really about 1am.

Anybody experience anything similar? How did you fix it?

1 Reply

Does the "incorrect" time match the output of "date -u"? If so, it's probably storing times in UTC and displaying your local time zone to you. This is probably actually the "correct" behavior (as MySQL DATETIME columns do not have a timezone attribute IIRC), but it does need to be handled by your application or framework.

(Typically, the best approach to handling time is to store it in UTC, and convert to/from local time as close to the human as possible.)

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct