js--------1.时间

 1 //获取当前时间 yyyy-MM-dd
 2 function getNowFormatDate() {
 3     var date = new Date();
 4     var seperator1 = "-";
 5     var seperator2 = ":";
 6     var month = date.getMonth() + 1;
 7     var strDate = date.getDate();
 8     if (month >= 1 && month <= 9) {
 9         month = "0" + month;
10     }
11     if (strDate >= 0 && strDate <= 9) {
12         strDate = "0" + strDate;
13     }
14     var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
15     return currentdate;
16 }
 1 //获取当前日期,个位数用0占位
 2 function getNowWithLine() {
 3     var date = new Date();
 4     var seperator1 = "/";
 5     var seperator2 = ":";
 6     var month = date.getMonth() + 1;
 7     var strDate = date.getDate();
 8     if (month >= 1 && month <= 9) {
 9         month = "0" + month;
10     }
11     if (strDate >= 0 && strDate <= 9) {
12         strDate = "0" + strDate;
13     }
14     var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
15     return currentdate;
16 }
 1 //获取指定日期的前几天日期或后几天日期
 2 function getDateFromCurrentDate(fromDate, dayInterval) {
 3 
 4     var curDate = new Date(Date.parse(fromDate.replace(/-/g, "/")));
 5     curDate.setDate(curDate.getDate() + dayInterval);
 6     var year = curDate.getFullYear();
 7     var month = (curDate.getMonth() + 1) < 10 ? "0" + (curDate.getMonth() + 1) : (curDate.getMonth() + 1);
 8     var day = curDate.getDate() < 10 ? "0" + curDate.getDate() : curDate.getDate();
 9     return year + "-" + month + "-" + day;
10 };
 1 //当前日期加n天 返回日期 yyyy-MM-dd
 2 function getFormatDate(addDay) {
 3     var date = new Date();
 4     date.setDate(date.getDate() + addDay);
 5     var seperator1 = "-";
 6     var month = date.getMonth() + 1;
 7     var strDate = date.getDate();
 8     if (month >= 1 && month <= 9) {
 9         month = "0" + month;
10     }
11     if (strDate >= 0 && strDate <= 9) {
12         strDate = "0" + strDate;
13     }
14     var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
15     return currentdate;
16 }

猜你喜欢

转载自www.cnblogs.com/chocolatexll/p/9274853.html
今日推荐