1.JQuery获取当前日期
var now = new Date();now = new Date(now.getTime() + 86400000);var year= now.getFullYear(), month= (now.getMonth() + 1).toString(), day = now .getDate().toString();if (month.length == 1) {month= '0' + month;}if (day .length == 1) {day = '0' + day ;}var dates=([year, month, day ].join('-'));console.log(dates);
结果如图:
2.JQuery获取当前月份的第一天与倒数第二天
var now = new Date();var month = now.getMonth() + 1;//js获取到的是月份是 0-11 所以要加1var year = now.getFullYear();var nextMonthFirstDay = new Date([year,month + 1,1].join('-')).getTime();var oneDay = 1000 * 24 * 60 * 60;var monthLast = new Date(nextMonthFirstDay - oneDay).getDate()var nowMonthFirstDay=[year,month,1].join('-')var nowMonthLastSecondDay=[year,month,monthLast].join('-')console.log(nowMonthFirstDay);//当前月的第一天console.log(nowMonthLastSecondDay)//当前月的倒数第二天
结果如图:
2.JQuery获取当前月份的某一天如当前月的15号
var now = new Date();var month = now.getMonth() + 1;//js获取到的是月份是 0-11 所以要加1var year = now.getFullYear();var nextMonthFirstDay = new Date([year,month + 1,1].join('-')).getTime();var oneDay = 1000 * 24 * 60 * 60*14;var monthLast = new Date(nextMonthFirstDay + oneDay).getDate()var nowMonthFifteenthDay=[year,month,monthLast].join('-')console.log(nowMonthFifteenthDay)//当前月的15号
希望以上内容可以帮助到你!
如有其他方法,欢迎交流学习!
如果觉得《#JavaScript JQuery怎么获取当前系统时间 及指定日期时间》对你有帮助,请点赞、收藏,并留下你的观点哦!