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());
原文地址:https://www.cnblogs.com/xinyibufang/p/7246011.html