日期范围根据jquery中的月份?

时间:2014-02-01 06:54:49

标签: javascript jquery

我正在尝试在点击按钮时在容器标题中显示日期范围。单击按钮,它将获取它的值并显示它。

var date = new Date,day = date.getDate(),month = date.getMonth() + 1,                   
year = date.getFullYear(),hour = date.getHours(),minute = date.getMinutes(),
seconds = date.getSeconds(),ampm = hour > 12 ? "PM" : "AM";

hour = hour % 12;
hour = hour ? hour : 12; 

minute = minute > 9 ? minute : "0" + minute;
seconds = seconds > 9 ? seconds : "0" + seconds;
hour = hour > 9 ? hour : "0" + hour;


date = month + "/" + (day-6) + "/" + year + " " + hour + ":" + minute + " " + ampm + " - " + month + "/" + day + "/" + year + " " + hour + ":" + minute + " " + ampm;
// date holds in the format "12/16/2011 08:14 PM"
$('#panelid').text(date); //panelid is where date range will be shown

因为我在10日之后正在研究这个代码,所以我没有遇到这个问题,但现在日间范围变得像 这个:2 / -5 / 2014 11:51 AM - 2/1/2014 11:51 AM

我该如何解决这个问题?任何建议。

0 个答案:

没有答案