.toLocaleDateString()在Firefox中不起作用

a1a*_*anm 5 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>
Run Code Online (Sandbox Code Playgroud)

tim*_*ood 4

根据 Mozilla 文档,该格式可能会因用户位置和计算机设置的不同而有很大差异。

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

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