Open In App

Ruby | DateTime httpdate() function

Improve
Improve
Like Article
Like
Save
Share
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 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 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


Last Updated : 09 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads