js获取当前日期

js获取当前日期方法(YYYY-MM-DD HH:MM:SS格式)

var myDate = new Date((new Date).getTime() + 8*60*60*1000);

var time = myDate.toJSON().split('T').join(' ').substr(0,19);

js获取当前日期方法(YYYY-MM-DD 格式)

var date = new Date();

var seperator1 = "-";

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 + seperator1 + month + seperator1 + strDate;

 

你可能感兴趣的:(javascript,前端,html)