簡単なJavascriptで日付を操作しようとしています。コードは次のとおりです。
var newDate = new Date("2013-07-23" + " 12:00:00");
console.log(newDate.toString());
newDate = new Date(newDate.getTime() - (24 * 60 * 60 * 1000));
console.log(newDate.toString());
var date = newDate.getFullYear() + "-" + ("0" + (newDate.getMonth() + 1)).slice(-2) + "-" + ("0" + newDate.getDate()).slice(-2);
console.log(date);
本質的に、私は変換しています
2013-07-23 -> Jul 22 2013 12:00:00 GMT+1000 -> 2013-07-22
Chrome で問題なく動作します。このFiddleを介してコードをテストできます。それはいつも戻ってくる
"Invalid Date"
"Invalid Date"
"NaN-aN-aN"
console.logs
ただし、Firefoxの 3 つについては次のとおりです。
Tue Jul 23 2013 12:00:00 GMT+1000 (E. Australia Standard Time)
Mon Jul 22 2013 12:00:00 GMT+1000 (E. Australia Standard Time)
2013-07-22
クロム用。