js--------1.时间
生活随笔
收集整理的這篇文章主要介紹了
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 }?
轉載于:https://www.cnblogs.com/chocolatexll/p/9274853.html
總結
以上是生活随笔為你收集整理的js--------1.时间的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python模块之lib2to3(py2
- 下一篇: D. Relatively Prime