to_s()
Returns a string representing time. Equivalent to calling Time#strftime with a format string of “%Y-%m-%d %H:%M:%S %z” for a local time and “%Y-%m-%d %H:%M:%S UTC” for a UTC time.
Time.now.to_s #=> "2007-10-05 16:09:51 +0900" Time.now.utc.to_s #=> "2007-10-05 07:09:51 UTC"
static VALUE time_to_s(VALUE time) { struct time_object *tobj; char buf[128]; int len; GetTimeval(time, tobj); if (tobj->tm_got == 0) { time_get_tm(time, tobj->gmt); } if (tobj->gmt == 1) { len = rb_strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S UTC", &tobj->tm, &tobj->ts, tobj->gmt); } else { len = rb_strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %z", &tobj->tm, &tobj->ts, tobj->gmt); } return rb_str_new(buf, len); }