Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Java脚本:新的日期格式不适用于11月和12月_Javascript - Fatal编程技术网

Javascript Java脚本:新的日期格式不适用于11月和12月

Javascript Java脚本:新的日期格式不适用于11月和12月,javascript,Javascript,我正在尝试更改我的日期格式 var d = new Date(); var curr_year = d.getFullYear(); var curr_Month = d.getMonth() +1; var curr_date = d.getDate(); var todayDate = var tDate = ( curr_Mo

我正在尝试更改我的日期格式

                var d = new Date();
                var curr_year = d.getFullYear();
                var curr_Month = d.getMonth() +1;
                var curr_date = d.getDate();
                var todayDate =  var tDate =   ( curr_Month +"/"+curr_date +"/"+ curr_year);
这一切都很好,但11月份显示的是10,而不是11,12月份显示的是11,而不是12…其余月份都很好

注意:这个问题只存在于mozilla和opera中,在InternetExplorer中它工作正常

有什么想法吗


谢谢,看起来很好。您使用什么浏览器(尽管我认为这无关紧要)?

您的代码应该无误地输出
“2011年11月23日”

对于
Date
元素,
getMonth()
是基于0的。一月到十二月显示为0-11

getMonth

根据本地时间返回指定日期中的月份(0-11)


这对我来说很好,产生了
11/23/2011
,这是我的时区中截至此答案的当前日期,尽管是奇怪的美国格式:-)

这在Firefox 8和IE 9中通过以下HTML文件进行了测试:

<html><head></head><body><script language="javascript">
var d = new Date();
var curr_year = d.getFullYear();
var curr_Month = d.getMonth() + 1;
var curr_date = d.getDate();
var todayDate =  (curr_Month + "/" + curr_date + "/" + curr_year);
alert (todayDate);
</script></body></html>
Firefox 8为您提供:

[23:12:17.613] syntax error @ file:///C:/Users/Pax/Documents/xyz.html:6

您将1添加到正确的月份,这样所有操作都会正常进行。您使用什么作为Date()构造函数参数来测试这些日期,请记住它们必须是日历日期的-1。@junaidp您的代码对我来说很好。您在哪个浏览器上测试?在我看来,问题中的错误不在日期内。抱歉,已更改我的问题(已编辑)我希望它的格式为mm/dd/yyyy输出是什么?在这里工作得很好:在Internet explorer中工作得很好,但这个问题出现在mozilla和chrome中
[23:12:17.613] syntax error @ file:///C:/Users/Pax/Documents/xyz.html:6