ruby - Rails: Get the DateTime format returned using Jbuilder -
i noticed when returning field type datetime in jbuilder : "2016-11-25t13:25:06.024z"
but when in .html.erb page display field "2016-12-21 09:35:05 utc"
my question how format of jbuilder in html.erb.
what you're seeing in json standard iso-8601 formatted timestamp time in utc (hence z
). can format in rails conveniently named iso8601
method:
> time.now.utc.iso8601 => "2016-12-22t04:59:25z"
the utc
call there ensure time in utc, don't need doesn't hurt , can prevent problems.
if want match precision you're getting jbuilder, include precision in iso8601
call:
> time.now.utc.iso8601(3) => "2016-12-22t05:01:21.512z"
Comments
Post a Comment