.toLocaleDateString()在Firefox中不起作用

时间:2011-11-03 21:39:14

标签: javascript firefox

我有下面的代码,打印出从现在起10个工作日的日期。在Opera和Chrome中,它可以按照我的预期和打印方式工作: 2011年11月17日,星期四

然而,在Firefox(6.0.2)中,它打印出来:11/17/2011

有谁知道为什么日期不会在Firefox中打印成字符串?

<script type="text/javascript">
    function businessDays(n){
        var D=new Date();
        var num=Math.abs(n);
        var tem,count=0;
        var dir= (n<0)? -1: 1;
        while(count< num){
            D= new Date(D.setDate(D.getDate()+dir));
            tem=D.getDay();
            if(tem!=0 && tem!=6) ++count;
        }
        return D;
    }
    var D=businessDays(10).toLocaleDateString(); //string
    document.write(D);
</script>

1 个答案:

答案 0 :(得分:4)

根据Mozilla文档,格式可能会因用户的位置和计算机设置而异。

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/toLocaleDateString

  

确切的格式取决于平台,区域设置和用户的设置。