getMonth在javascript中给出了上个月 [英] getMonth in javascript gives last month
本文介绍了getMonth在javascript中给出了上个月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用一个datepicker,日期格式为Sun Jul 7 00:00:00 EDT 2013。
即使这个月说七月,如果我做一个getMonth,它给了我上个月。
I am using a datepicker which gives a date in the format Sun Jul 7 00:00:00 EDT 2013. Even though the month says July, if I do a getMonth, it gives me the previous month.
var d1 = new Date("Sun Jul 7 00:00:00 EDT 2013");
d1.getMonth());//gives 6 instead of 7
我是什么做错了?
推荐答案
因为 getmonth()从0开始。您可能需要将 d1.getMonth()+ 1
实现你想要的。
Because getmonth() start from 0. You may want to have d1.getMonth() + 1
to achieve what you want.
这篇关于getMonth在javascript中给出了上个月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文