APIdock / Ruby
/
method

nsec

ruby latest stable - Class: Time
nsec()
public

Returns the number of nanoseconds for time.

t = Time .now  #=> 2007年11月17日 15:18:03 +0900
"%10.9f" % t.to_f  #=> "1195280283.536151409"
t.nsec  #=> 536151406

The lowest digits of #to_f and #nsec are different because IEEE 754 double is not accurate enough to represent the exact number of nanoseconds since the Epoch.

The more accurate value is returned by #nsec.

static VALUE
time_nsec(VALUE time)
{
 struct time_object *tobj;
 GetTimeval(time, tobj);
 return rb_to_int(w2v(wmulquoll(wmod(tobj->timew, WINT2WV(TIME_SCALE)), 1000000000, TIME_SCALE)));
}

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