APIdock / Ruby
/
method

strptime

ruby latest stable - Class: Date
strptime(p1 = v1, p2 = v2, p3 = v3)
public

Parses the given representation of date and time with the given template, and creates a date object. strptime does not support specification of flags and width unlike strftime.

Date .strptime ('2001年02月03日', '%Y-%m-%d') #=> #<Date: 2001年02月03日 ...>
Date .strptime ('03-02-2001', '%d-%m-%Y') #=> #<Date: 2001年02月03日 ...>
Date .strptime ('2001-034', '%Y-%j') #=> #<Date: 2001年02月03日 ...>
Date .strptime ('2001-W05-6', '%G-W%V-%u') #=> #<Date: 2001年02月03日 ...>
Date .strptime ('2001 04 6', '%Y %U %w') #=> #<Date: 2001年02月03日 ...>
Date .strptime ('2001 05 6', '%Y %W %u') #=> #<Date: 2001年02月03日 ...>
Date .strptime ('sat3feb01', '%a%d%b%y') #=> #<Date: 2001年02月03日 ...>

See also strptime(3) and #strftime.

static VALUE
date_s_strptime(int argc, VALUE *argv, VALUE klass)
{
 VALUE str, fmt, sg;
 rb_scan_args(argc, argv, "03", &str, &fmt, &sg);
 switch (argc) {
 case 0:
 str = rb_str_new2("-4712年01月01日");
 case 1:
 fmt = rb_str_new2("%F");
 case 2:
 sg = INT2FIX(DEFAULT_SG);
 }
 {
 VALUE argv2[2], hash;
 argv2[0] = str;
 argv2[1] = fmt;
 hash = date_s__strptime(2, argv2, klass);
 return d_new_by_frags(klass, hash, sg);
 }
}

AltStyle によって変換されたページ (->オリジナル) /