Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这种DateTime格式:
DateTime
var1 = 2014-06-10T18:49:59+00:00
我想转换成这种格式:
var2 = 2014-06-10 18:49:59 UTC
谢谢!
尝试:
Time.parse(var1.to_s).utc
假设 var1 持有一个 DateTime 对象。
使用 strftime:
var2 = var1.strftime("%Y-%m-%d %H:%M:%S %z")
有关更多格式字符串,请参阅 strftime 文档
http://www.ruby-doc.org/core-2.0/Time.html