Skip to content

Instantly share code, notes, and snippets.

@pinzolo
Last active January 18, 2016 06:19
Show Gist options
  • Save pinzolo/e93ec01578e404aa1c8f to your computer and use it in GitHub Desktop.
Save pinzolo/e93ec01578e404aa1c8f to your computer and use it in GitHub Desktop.
new Date(datetime_text) した時にChrome, Firefox, IE でパース可能な形式にする
module TimeWithZoneHelper
def format_for_js1(time_with_zone)
time_with_zone.to_s.gsub(/-/, '/')
end
def format_for_js2(time_with_zone)
time_with_zone.to_json.gsub(/\"/, '')
end
end
# to_s(:js) にするなら config/initializers/time_formats.rb にて
Time::DATE_FORMATS[:js] = '%Y/%m/%d %H:%M:%S %z'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment