Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Time#to_s

() -> ::String
to_s → string

Returns a string representation of self, without subseconds:

Example
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:

Example
t.ctime   # => "Sun Dec 31 23:59:59 2000"
t.inspect # => "2000-12-31 23:59:59.5 +000001"
See also #to_r #to_time #to_json #tuesday? also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0