js获取当前时间
获取当前时间 yyyy-MM-dd
function getNowFormatDate ( ) {
var date = new Date ( ) ;
var seperator1 = "-" ;
var seperator2 = ":" ;
var month = date. getMonth ( ) + 1 ;
var strDate = date. getDate ( ) ;
if ( month >= 1 && month <= 9 ) {
month = "0" + month;
}
if ( strDate >= 0 && strDate <= 9 ) {
strDate = "0" + strDate;
}
var currentdate = date. getFullYear ( ) + seperator1 + month + seperator1 + strDate;
return currentdate;
}
获取指定日期的前几天日期或后几天日期
function getDateFromCurrentDate ( fromDate, dayInterval ) {
var curDate = new Date ( Date. parse ( fromDate. replace ( / - / g , "/" ) ) ) ;
curDate. setDate ( curDate. getDate ( ) + dayInterval) ;
var year = curDate. getFullYear ( ) ;
var month = ( curDate. getMonth ( ) + 1 ) < 10 ? "0" + ( curDate. getMonth ( ) + 1 ) : ( curDate. getMonth ( ) + 1 ) ;
var day = curDate. getDate ( ) < 10 ? "0" + curDate. getDate ( ) : curDate. getDate ( ) ;
return year + "-" + month + "-" + day;
} ;
获取指定日期的前几天日期或后几天日期
function getFormatDate ( addDay ) {
var date = new Date ( ) ;
date. setDate ( date. getDate ( ) + addDay) ;
var seperator1 = "-" ;
var month = date. getMonth ( ) + 1 ;
var strDate = date. getDate ( ) ;
if ( month >= 1 && month <= 9 ) {
month = "0" + month;
}
if ( strDate >= 0 && strDate <= 9 ) {
strDate = "0" + strDate;
}
var currentdate = date. getFullYear ( ) + seperator1 + month + seperator1 + strDate;
return currentdate;
}
参考文章:https://www.cnblogs.com/chocolatexll/p/9274853.html .