红宝石 |日期时间 httpdate()函数
DateTime#httpdate() :httpdate()是一个 DateTime 类方法,它通过根据某些 RFC 2616 格式从字符串解析返回一个新的 DateTime 对象。
Syntax: DateTime.httpdate()
Parameter: DateTime values
Return: A new DateTime object by parsing from a string according to some RFC 2616 format.
示例 #1:
# Ruby code for DateTime.httpdate() method
# loading library
require 'date'
# declaring DateTime value
date_a = DateTime.httpdate('Sat, 03 Feb 2001 04:05:06 GMT')
# httpdate method
puts "DateTime httpdate form : #{date_a}\n\n"
输出 :
DateTime httpdate form : 2001-02-03T04:05:06+00:00
示例 #2:
# Ruby code for DateTime.httpdate() method
# loading library
require 'date'
# declaring DateTime value
date_a = DateTime.httpdate('Tue, 01 Mar 2003 04:15:06 GMT')
# httpdate method
puts "DateTime httpdate form : #{date_a}\n\n"
输出 :
DateTime httpdate form : 2003-03-01T04:15:06+00:00