JS以指定格式獲取當前日期


 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     }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM