JS获取当前日期
YYYY-MM-DD
function getNowFormatDate ( ) {
var date = new Date ( ) ;
var separator = "-" ;
var year = date. getFullYear ( ) ;
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 = year + separator + month + separator + strDate;
return currentdate;
}
YYYY/MM/DD
function getNowFormatDate ( ) {
var date = new Date ( ) ;
var separator = "/" ;
var year = date. getFullYear ( ) ;
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 = year + separator + month + separator + strDate;
return currentdate;
}
模板
function getNowFormatDate ( seperator ) {
var date = new Date ( ) ;
var year = date. getFullYear ( ) ;
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 = year + seperator + month + seperator + strDate;
return currentdate;
}