我实施的的Facebook 的应用程序和使用的 AJAX / JSON 的。
I am implementing a Facebook application and using AJAX/JSON.
然而 JSON 的返回的结构具有这种格式 2010-05-30T06:14:00Z
However the JSON structures that are returned have this format 2010-05-30T06:14:00Z
.
我打电话 Game.all.to_json
在控制器动作。
I'm calling Game.all.to_json
in controller action.
我怎样才能将其转换为正常的日期格式?
How can I convert them to a normal date format?
时更容易使用从服务器端或客户端做的 FBJS 的? 有很多的bug的 FBJS 的。
Is it easier to do it from the server side or the client side using fbjs? There are a lot of bugs with fbjs.
所以,我将使用从服务器端
使用的解决方案preFER(的活动记录
)。就像将数据发送 JSON
结构之前。
So i would prefer using a solution from the Server side
using (Active Records
). Like converting the data before sending the JSON
structures.
我说我自己的自定义格式的JSON我回来的方法是猴子补丁添加到的ActiveSupport TimeWithZone类。
The way I added my own custom format to the json I was returning was to add a monkey patch to the ActiveSupport TimeWithZone class.
添加文件在config /初始化文件夹中有如下内容:
Add a file in the config/initializers folder with the following contents:
class ActiveSupport::TimeWithZone
def as_json(options = {})
strftime('%Y-%m-%d %H:%M:%S')
end
end