zl程序教程

您现在的位置是:首页 >  后端

当前栏目

JS以指定格式获取当前日期

JS日期 获取 格式 指定 当前
2023-09-11 14:22:18 时间
 1 //获取当前时间,格式YYYY-MM-DD
 2     function getNowFormatDate() {
 3         var date = new Date();
 4         var seperator1 = "-";
 5         var year = date.getFullYear();
 6         var month = date.getMonth() + 1;
 7         var strDate = date.getDate();
 8         if (month >= 1 && month <= 9) {
 9             month = "0" + month;
10         }
11         if (strDate >= 0 && strDate <= 9) {
12             strDate = "0" + strDate;
13         }
14         var currentdate = year + seperator1 + month + seperator1 + strDate;
15         return currentdate;
16     }