在Ruby中将Time类对象转换为RFC3339 [英] converting Time class object to RFC3339 in Ruby

查看:61
本文介绍了在Ruby中将Time类对象转换为RFC3339的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google Calendar API(v2)与时间相关的查询必须为RFC3339格式.在需要时间""之后查询时间类时,我看不到rfc3339方法.

Google Calendar API(v2)'s time-related query is required to be RFC3339-formatted. When I looked up Time class after 'require "time"', I could not see rfc3339 method.

推荐答案

如果使用的是ActiveRecord,则可以使用to_datetime方法将时间转换为DateTime对象.

If you are using ActiveRecord, you can use the to_datetime method to convert the time to a DateTime object.

Time.now.to_datetime.rfc3339 #=> "2014-11-06T10:40:54+11:00" 

请参阅:
http://www.ruby-doc. org/stdlib-2.4.1/libdoc/date/rdoc/Time.html .

这篇关于在Ruby中将Time类对象转换为RFC3339的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆