JS:Safari的新Date().getTime()提供了与Chrome不同的结果 [英] JS: Safari new Date().getTime() gives different results from Chrome
本文介绍了JS:Safari的新Date().getTime()提供了与Chrome不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做
new Date().getTime();
Chrome和Safari的结果不同.
Chrome and Safari have different results.
如何使其工作?
另外,我想摆脱这个问题:
Plus, I want to get rid of this:
var n = new Date();
var nYear = n.getFullYear();
var nMonth = n.getMonth()+1;
if (nMonth<10)
nMonth = "0" + nMonth;
var nDate = n.getDate();
if (nDate<10)
nDate = "0" + nDate;
var date = nYear + "-" + nMonth + "-" + nDate;
var nHours = n.getHours();
if (nHours<10)
nHours = "0" + nHours;
var nMinutes = n.getMinutes();
if (nMinutes<10)
nMinutes = "0" + nMinutes;
var startHour = nHours + ":" + nMinutes;
并将其变成这样:
$date = date("Y-m-d");
$startHour = date("H:i");
推荐答案
In this old post is the solution -> Invalid date in safari
查看了 datejs文档之后,使用它,你的问题应该 可以使用以下代码解决:
After looking at datejs documentation, using it, your problem should be solved using code like this:
var myDate1 = Date.parseExact("29-11-2010", "dd-MM-yyyy");
var myDate2 = Date.parseExact("11-29-2010", "MM-dd-yyyy");
var myDate3 = Date.parseExact("2010-11-29", "yyyy-MM-dd");
var myDate4 = Date.parseExact("2010-29-11", "yyyy-dd-MM");
这篇关于JS:Safari的新Date().getTime()提供了与Chrome不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文