简体   繁体   中英

Ruby on Rails / SQL Server datetime

I'm having some problem with date time. My local timezone is UTC +0800 .

In the SQL Server, when I open up SQL Server Management Studio Express, the datetime shows as 13/8/2015 9:05:00 AM .

With Rails on default timezone, I get the time in angular as "2015-08-13T09:05:00.000Z"

When I do $filter('date')(date, "HH:mm Z") , I get 17:05 +0800

When I do $filter('date')(date, "HH:mm Z", "+0800") , I still get 17:05 +0800

I tried to change rails timezone to UTC +0800 , I get the time in angular as 2015-08-13T17:05:00.000+08:00

When I do $filter('date')(date, "HH:mm Z") , I get 17:05 +0800

When I do $filter('date')(date, "HH:mm Z", "+0800") , I still get 17:05 +0800

I am confused. How can I get the $filter result to show the time 9:05

EDIT: i watched the rails cast video and tried d.AssignedDateTime_before_type_cast and it's giving me 2015-08-13 09:05:00 UTC . So the problem is Rails think that the datetime stored in SQL Server Database is UTC. That datetime is given to me from a Microsoft ERP system, is there any way I can make rails not think it's a UTC time? Changing the config timezone in application.rb did not work.

除了在application.rb config.time_zone之外,更改config.active_record.default_timezone也可以。

Have you watched this Railscast ? It might help you with configuring Rails with the right timezone.

Once you have the right times coming out of the database and being rendered in your JSON response, I expect the Angular problem should be taken care of.

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