I am making an rails app and getting a date back from the server from an ajax call. The received date from the server is 2012-12-23 18:44:00 UTC
. When I do this newYear = new Date(data)
(where data is the received date) I get Sun Dec 23 2012 19:44:00 GMT+0100 (CET)
in Chrome and Invalid Date
in Safari.
(I actually want to get the date from the server and convert it to milliseconds so I can compare it to todays date.)
So it works fine in Chrome, but not in Safari.
How can I fix this problem?
.js file:
$ ->
$(document).ready ->
$.post "/get_time", (data) ->
newYear = new Date(data)
today = new Date().getTime()
newYearMS = newYear.getTime()
$("#ggg").html newYearMS
if newYearMS < today
$("body").css "background-image", "url('/assets/HypePlay.png')"
else
$("#play_button").hide()
$("#counter").countdown
until: newYear
format: "HMS"
expiryUrl: "/"
$('#hhh').html data
return_time function from controller:
def return_time
date = Item.where(:end => Time.zone.now .. '2040-12-28 08:08:00').order("launch ASC").limit(1).first.launch
render text: date
end