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

查看:146
本文介绍了.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/Reference/Global_Objects/Date/toLocaleDateString


具体格式取决于平台,区域设置和用户设置。

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

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

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