获取今天、昨天、本周、上周、本月、上个月(实例共享)

获取今天、昨天、本周、上周、本月、上个月(实例共享)
如果你不多说,看看代码:
获取今天
无功nowdate =新(日期); / /日期
console.log(nowdate);
今天是本周的头几天。
无功nowdayofweek = nowdate.getday();
console.log(nowdayofweek);
当前日期
今天,nowdate.getdate(VAR);
console.log(时代);
当前月份
无功nowmonth = nowdate.getmonth();
console.log(nowmonth);
当前年份
无功nowyear = nowdate.getfullyear();
console.log(nowyear);
/ /无功nowhours = nowdate.gethours();
/ /无功nowminutes = nowdate.getminutes();
/ /无功nowseconds = nowdate.getseconds();
nowyear =(nowyear<2000)1900:0; / /
console.log(nowyear);
无功lastmonthdate =新(日期); / /日期的最后一个月
console.log(lastmonthdate);
(1)lastmonthdate.setdate;
console.log(lastmonthdate.setdate(1));
lastmonthdate.setmonth(lastmonthdate.getmonth)-(1);
console.log(lastmonthdate.setmonth(lastmonthdate.getmonth)-(1));
去年lastmonthdate.getyear(VaR)=;
console.log(去年);
上个月,lastmonthdate.getmonth(VAR);
console.log(上个月);
/ /日期格式:yyyy-mm-dd
功能formatDate(日期){
无功myyear = date.getfullyear();
无功mymonth = date.getmonth()+ 1;
无功myweekday = date.getdate();
/ /无功时间= date.gethours();
/ /无功myminutes = date.getminutes();
/ /无功myseconds = date.getseconds();
如果(mymonth<10){
mymonth =0+ mymonth;
}
如果(myweekday<10){
myweekday =0+ myweekday;
}
/ /如果(时间<10){
/ /时间= 0 +时间;
/
免责声明:本网信息来自于互联网,目的在于传递更多信息,并不代表本网赞同其观点。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,并请自行核实相关内容。本站不承担此类作品侵权行为的直接责任及连带责任。如若本网有任何内容侵犯您的权益,请及时联系我们,本站将会在24小时内处理完毕。
相关文章
返回顶部