My object model has a attribute named "start_at
" which is sotred in PostgreSQL database.
Inside the database table, the type of "start_at
" is "time without time zone" and one object start_at value is e.g. 10:20:00.
However, when I render this time value to my index.html.haml
view by using
%td =myobj.start_at
, the view page always show "Sat Jan 01 10:20:00 UTC 2000" ins开发者_如何学编程tead of 10:20:00.
How to get rid of it to show only 10:20:00 instead of the long string?
What about:
myobj.start_at.strftime('%H:%M:%S')
Check resource here: http://www.ruby-doc.org/core/classes/Time.html#M000392
use timeobj.strftime("%H:%M:%S")
you can view all the options for strftime
here
精彩评论