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());

 

posted @ 2017-07-27 17:14  XinYiBuFang  阅读(6236)  评论(0编辑  收藏  举报