Class: DateTime

Inherits:
Object show all
Defined in:
lib/to-javascript/encoders/date_time.rb

Instance Method Summary collapse

Instance Method Details

#to_js(options = nil) ⇒ Object

Returns a Javascript string to create a Date object of the same datetime.

Example:

DateTime.civil(2005,2,1,15,15,10).to_js
# => "new Date(2005/02/01 15:15:10 +0000)"


7
8
9
# File 'lib/to-javascript/encoders/date_time.rb', line 7

def to_js(options = nil)
  ActiveSupport::JS::Code.new "new Date('#{strftime("%Y/%m/%d %H:%M:%S %z")}')"
end