class Time
Public Class Methods
timestamp → int
click to toggle source
Returns a nanosecond timestamp on the system's monotonic clock.
Time.timestamp #=> 17817203921822
static VALUE time_s_timestamp(VALUE klass) { VALUE t; #ifdef HAVE_CLOCK_GETTIME struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) { rb_sys_fail("clock_gettime"); } t = rb_uint2big(ts.tv_sec*1000000000 + ts.tv_nsec); #else struct timeval tv; if (gettimeofday(&tv, 0) < 0) { rb_sys_fail("gettimeofday"); } t = rb_uint2big(tv.tv_sec*1000000000 + tv.tv_usec*1000); #endif return t; }
unix_microtime → float
click to toggle source
Returns the current time as a floating-point number of seconds since the Epoch.
Time.unix_microtime #=> 1363352771.315240
static VALUE time_s_unix_microtime(VALUE klass) { double t; #ifdef HAVE_CLOCK_GETTIME struct timespec ts; if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { rb_sys_fail("clock_gettime"); } t = (double)ts.tv_sec; t += ((double)ts.tv_nsec / 1000000000.0); #else struct timeval tv; if (gettimeofday(&tv, 0) < 0) { rb_sys_fail("gettimeofday"); } t = (double)tv.tv_sec; t += ((double)tv.tv_usec / 1000000.0); #endif return rb_float_new(t); }
unix_timestamp → int
click to toggle source
unix_time → int
Returns the current time as an integer number of seconds since the Epoch.
Time.unix_timestamp #=> 1363352771 Time.unix_time #=> 1363352771
static VALUE time_s_unix_timestamp(VALUE klass) { return LONG2NUM( time(NULL) ); }
Returns the current time as an integer number of seconds since the Epoch.
Time.unix_timestamp #=> 1363352771 Time.unix_time #=> 1363352771
static VALUE time_s_unix_timestamp(VALUE klass) { return LONG2NUM( time(NULL) ); }
Also aliased as: unix_time