Home > Web Front-end > JS Tutorial > body text

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

零到壹度
Release: 2018-04-09 10:13:51
Original
2678 people have browsed it

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();     
}
Copy after login
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();     
}
Copy after login

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();     
}
Copy after login

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();     
}
Copy after login

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();     
}
Copy after login
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();     
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template