Q:

How to format a Time as "2015-10-09T23:51:13.449Z" in Rails?

Time.now.utc.iso8601
=> "2015-10-09T23:51:13Z"

This format is close to the desired format 2015-10-09T23:51:13.449Z except it does not show the decimal of the seconds.
FWIW, this is the format that comes out of Mongoid. I think it is the same as Rails AR format.
Rails 4.2.4

A:

If you want the extra precision, do it yourself with strftime:
Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%LZ')

The %L is the extra bit you're looking for:

%L - Millisecond of the second (000..999)
  The digits under millisecond are truncated to not produce 1000.

