简体   繁体   中英

Rails 2.3.14 - to_datetime returns UTC time

I have a following issue - I'm not using config.time_zone, so it should default to my server time zone (if I understand it correctly).

And in my rails console when I do something like

'Oct 12, 2012'.to_datetime 

it returns

Fri, 12 Oct 2012 00:00:00 +0000 

but when I run

'Oct 12, 2012'.to_date.end_of_day

I get the time zone I actually need:

2012-10-12 23:59:59 -0400 

Do you have any ideas why that can happen and how I can get it to work in the same time zone? I found this link - https://rails.lighthouseapp.com/projects/8994/tickets/864-string-to_datetime-doesn-t-take-into-account-timezone-or-second-fractions , but I thought it should be fixed.

Thanks!

It's likely that Rails 2.3.14 will be the end of the line for the Rails 2.3 series unless a major security update is required. This will likely go unpatched.

Maybe using to_date produces different results than to_datetime , so you may be able to work around this somehow.

Don't forget you can also tweak the time-zone of any DateTime object if required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM