红宝石 |日期时间 rfc2822()函数
DateTime#rfc2822() : rfc2822()是一个 DateTime 类方法,它根据一些典型的 RFC 3339 格式从字符串中解析返回一个新的 DateTime 对象。
Syntax: DateTime.rfc2822()
Parameter: DateTime values
Return: A new DateTime object by parsing from a string according to some typical RFC 3339 formats.
示例 #1:
# Ruby code for DateTime.rfc2822() method
# loading library
require 'date'
# declaring DateTime value
date_b = DateTime.rfc2822('Sat, 10 Mar 2015 03:08:02 +0400')
# rfc2822 method
puts "DateTime rfc2822 form : #{date_b}\n\n"
输出 :
DateTime rfc2822 form : 2015-03-10T03:08:02+04:00
示例 #2:
# Ruby code for DateTime.rfc2822() method
# loading library
require 'date'
# declaring DateTime value
date_a = DateTime.rfc2822('Mon, 3 Feb 2001 04:05:06 +0700')
# rfc2822 method
puts "DateTime rfc2822 form : #{date_a}\n\n"
输出 :
DateTime rfc2822 form : 2001-02-03T04:05:06+07:00