method

to_s

to_s(format = :default)
public

Returns a string of the object’s date and time. Accepts an optional format:

  • :default - default value, mimics Ruby 1.9 Time#to_s format.

  • :db - format outputs time in UTC :db time. See Time#to_formatted_s(:db).

  • Any key in Time::DATE_FORMATS can be used. See active_support/core_ext/time/conversions.rb.

1Note

Time in fixtures

hosiawak · Aug 17, 20091 thank

When creating fixtures you should use this method to set created_at/updated_at timestamps correctly:

eg:

This won't work as expected (created_at/updated_at will be nil) a one: episode: active1 play_id: 1 play_time: 20 country: United Kingdom created_at: <%= Time.parse('22:00 14 Aug 2009') %> updated_at: <%= Time.parse('22:00 14 Aug 2009') %>

but this will work as expected:

one: episode: active1 play_id: 1 play_time: 20 country: United Kingdom created_at: <%= Time.parse('22:00 14 Aug 2009').to_s(:db) %> updated_at: <%= Time.parse('22:00 14 Aug 2009').to_s(:db) %>