Method: Time#to_s

Defined in:
time.c

#to_sString

Returns a string representation of self, without subseconds:

t = Time.new(2000, 12, 31, 23, 59, 59, 0.5)
t.to_s    # => "2000-12-31 23:59:59 +0000"

Related: Time#ctime, Time#inspect:

t.ctime   # => "Sun Dec 31 23:59:59 2000"
t.inspect # => "2000-12-31 23:59:59.5 +000001"

Returns:

[View source]

4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
# File 'time.c', line 4361

static VALUE
time_to_s(VALUE time)
{
    struct time_object *tobj;

    GetTimeval(time, tobj);
    if (TZMODE_UTC_P(tobj))
        return strftimev("%Y-%m-%d %H:%M:%S UTC", time, rb_usascii_encoding());
    else
        return strftimev("%Y-%m-%d %H:%M:%S %z", time, rb_usascii_encoding());
}