Open In App

Ruby | DateTime httpdate() function

Last Updated : 09 Jan, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
DateTime#httpdate() : httpdate() is a DateTime class method which returns a new DateTime object by parsing from a string according to some RFC 2616 format.
Syntax: DateTime.httpdate() Parameter: DateTime values Return: A new DateTime object by parsing from a string according to some RFC 2616 format.
Example #1 : Ruby
# 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"
Output :
DateTime httpdate form : 2001-02-03T04:05:06+00:00

Example #2 : Ruby
# 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"
Output :
DateTime httpdate form : 2003-03-01T04:15:06+00:00


Similar Reads