首页 > 代码库 > JS 获取日期字符串

JS 获取日期字符串

效果图:

技术分享

 

代码:

 1                 var date = new Date();
 2                 var seperator1 = "-";
 3                 var seperator2 = ":";
 4                 var month = date.getMonth() + 1;
 5                 var strDate = date.getDate();
 6                 if (month >= 1 && month <= 9) {
 7                     month = "0" + month;
 8                 }
 9                 if (strDate >= 0 && strDate <= 9) {
10                     strDate = "0" + strDate;
11                 }
12                 var currentdate = date.getFullYear() + month + strDate;
13                 sweetAlert(currentdate.toString());

 

JS 获取日期字符串