.toLocaleDateString() 在 Firefox 中不起作用 [英] .toLocaleDateString() Not Working in Firefox

查看:33
本文介绍了.toLocaleDateString() 在 Firefox 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have the below code which prints out the date which is 10 working days from now. In Opera and Chrome it works as I expected and prints: Thursday, November 17, 2011

但是在 Firefox (6.0.2) 中它打印出来:11/17/2011

However in Firefox (6.0.2) it prints out: 11/17/2011

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

Does anyone know why the date isn't getting printed as a string in 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>

推荐答案

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

According to the Mozilla documentation, the format can vary wildly depending on the user's location and computer settings.

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

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

The exact format depends on the platform, locale and user's settings.

这篇关于.toLocaleDateString() 在 Firefox 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆