End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
DateTime.httpdate
DateTime.httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY]) → datetime
ext/date/date_core.c
View on GitHub ↗
static VALUE
datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
{
VALUE str, sg, opt;
rb_scan_args(argc, argv, "02:", &str, &sg, &opt);
if (!NIL_P(opt)) argc--;
switch (argc) {
case 0:
str = rb_str_new2("Mon, 01 Jan -4712 00:00:00 GMT");
case 1:
sg = INT2FIX(DEFAULT_SG);
}
{
int argc2 = 1;
VALUE argv2[2];
argv2[0] = str;
argv2[1] = opt;
if (!NIL_P(opt)) argc2++;
VALUE hash = date_s__httpdate(argc2, argv2, klass);
return dt_new_by_frags(klass, hash, sg);
}
}
Creates a new DateTime object by parsing from a string according to some RFC 2616 format.
Example
DateTime.httpdate('Sat, 03 Feb 2001 04:05:06 GMT') #=> #<DateTime: 2001-02-03T04:05:06+00:00 ...>
Raise an ArgumentError when the string length is longer than limit. You can stop this check by passing ‘limit: nil`, but note that it may take a long time to parse.