获取时间

前端之家收集整理的这篇文章主要介绍了获取时间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
                                        <pre><code>function curDateTime() {
   var d = new Date();
   var year = d.getFullYear();
   var month = d.getMonth() + 1;
   var date = d.getDate();
   var day = d.getDay();
   var curDateTime = year;
   if (month > 9)
      curDateTime = curDateTime + "-" + month;
   else
      curDateTime = curDateTime + "-0" + month;
   if (date > 9)
      curDateTime = curDateTime + "-"  + date;
   else
      curDateTime = curDateTime + "-0" + date;
   return curDateTime;

}
curDateTime()
"2019-03-21"

原文链接:https://www.f2er.com/note/411539.html

猜你在找的程序笔记相关文章