Home  >  Article  >  Web Front-end  >  How to get the time code of today, this week and this month in js

How to get the time code of today, this week and this month in js

零到壹度
零到壹度Original
2018-04-09 10:13:512625browse

The content of this article is to share with you how to use js to get the time code of today, this week and this month. It has a certain reference value. Friends in need can refer to it

function showToDay()     
{     
    var Nowdate=new Date();     
    M=Number(Nowdate.getMonth())+1     
    alert(Nowdate.getMonth()+"月,"+Nowdate.getDate()+"号,星期"+Nowdate.getDay());     
    return Nowdate.getYear()+"-"+M+"-"+Nowdate.getDate();     
}
rrree

First day of this week

function showTomorrow()
{     
    var tom=new Date();     
    tom.setDate(tom.getDate()+1);     
    M=Number(tom.getMonth())+1     
    return tom.getYear()+"-"+M+"-"+tom.getDate();     
}

Last day of this week

function showWeekFirstDay()     
{     
    var Nowdate=new Date();     
    var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);     
    M=Number(WeekFirstDay.getMonth())+1     
    return WeekFirstDay.getYear()+"-"+M+"-"+WeekFirstDay.getDate();     
}

First day of this month

function showWeekLastDay()     
{     
    var Nowdate=new Date();     
    var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);     
    var WeekLastDay=new Date((WeekFirstDay/1000+6*86400)*1000);     
    M=Number(WeekLastDay.getMonth())+1     
    return WeekLastDay.getYear()+"-"+M+"-"+WeekLastDay.getDate();     
}

Last day of this month

function showMonthFirstDay()     
{     
    var Nowdate=new Date();     
    var MonthFirstDay=new Date(Nowdate.getYear(),Nowdate.getMonth(),1);     
    M=Number(MonthFirstDay.getMonth())+1     
    return MonthFirstDay.getYear()+"-"+M+"-"+MonthFirstDay.getDate();     
}
function showMonthLastDay()     
{     
    var Nowdate=new Date();     
    var MonthNextFirstDay=new Date(Nowdate.getYear(),Nowdate.getMonth()+1,1);     
    var MonthLastDay=new Date(MonthNextFirstDay-86400000);     
    M=Number(MonthLastDay.getMonth())+1     
    return MonthLastDay.getYear()+"-"+M+"-"+MonthLastDay.getDate();     
}

The above is the detailed content of How to get the time code of today, this week and this month in js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn