APIdock / Ruby
/
method

to_r

ruby latest stable - Class: Time
to_r()
public

Returns the value of time as a rational number of seconds since the Epoch.

t = Time .now 
p t.to_r  #=> (1270968792716287611/1000000000)

This methods is intended to be used to get an accurate value representing the nanoseconds since the Epoch. You can use this method to convert time to another Epoch.

static VALUE
time_to_r(VALUE time)
{
 struct time_object *tobj;
 VALUE v;
 GetTimeval(time, tobj);
 v = w2v(rb_time_unmagnify(tobj->timew));
 if (!RB_TYPE_P(v, T_RATIONAL)) {
 v = rb_Rational1(v);
 }
 return v;
}

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