method
to_s
v1_8_7_330 -
Show latest stable
- Class:
Time
to_s()public
Returns a string representing time. Equivalent to calling Time#strftime with a format string of “%a %b %d %H:%M:%S %Z %Y”.
Time.now.to_s #=> "Wed Apr 09 08:56:04 CDT 2003"
/*
* call-seq:
* time.inspect => string
* time.to_s => string
*
* Returns a string representing <i>time</i>. Equivalent to calling
* <code>Time#strftime</code> with a format string of ``<code>%a</code>
* <code>%b</code> <code>%d</code> <code>%H:%M:%S</code>
* <code>%Z</code> <code>%Y</code>''.
*
* Time.now.to_s #=> "Wed Apr 09 08:56:04 CDT 2003"
*/
static VALUE
time_to_s(time)
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 = strftime(buf, 128, "%a %b %d %H:%M:%S UTC %Y", &tobj->tm);
}
else {
time_t off;
char buf2[32];
char sign = '+';
#if defined(HAVE_STRUCT_TM_TM_GMTOFF)
off = tobj->tm.tm_gmtoff;
#else
VALUE tmp = time_utc_offset(time);
off = NUM2INT(tmp);
#endif
if (off < 0) {
sign = '-';
off = -off;
}
sprintf(buf2, "%%a %%b %%d %%H:%%M:%%S %c%02d%02d %%Y",
sign, (int)(off/3600), (int)(off%3600/60));
len = strftime(buf, 128, buf2, &tobj->tm);
}
return rb_str_new(buf, len);
} Related methods
- Instance methods
- +
- -
- <=>
- _dump
- asctime
- ctime
- day
- dst?
- eql?
- getgm
- getlocal
- getutc
- gmt?
- gmt_offset
- gmtime
- gmtoff
- hash
- hour
- httpdate
- initialize_copy
- inspect
- isdst
- iso8601
- localtime
- marshal_dump
- marshal_load
- mday
- min
- mon
- month
- rfc2822
- rfc822
- sec
- strftime
- succ
- to_a
- to_f
- to_i
- to_s
- to_yaml
- tv_sec
- tv_usec
- usec
- utc
- utc?
- utc_offset
- w3cdtf
- wday
- xmlschema
- yday
- year
- zone
- Class methods
- _load
- at
- gm
- httpdate
- local
- mktime
- new
- now
- parse
- rfc2822
- times
- utc
- w3cdtf
- xmlschema
- yaml_new
- zone_offset
- Private methods
-
apply_offset -
make_time -
month_days -
zone_utc? -
to_date -
to_datetime