如何写2018-01-23,而不是2018-1-23
获取本年 var year=new Date().getFullYear() ;
获取本月 var month = new Date().getMonth() + 1 < 10 ? "0" + (new Date().getMonth() + 1) : new Date().getMonth() + 1;获取本日 var day = new Date().getDate() < 10 ? "0" + new Date().getDate() : new Date().getDate();
赋值 $("#date").html(year+'-'+month+'-'+day);
本文介绍了一种使用JavaScript来确保日期格式正确显示的方法,具体为确保月份和日期不足两位时前面补零,例如将2018-1-23显示为2018-01-23。
175

被折叠的 条评论
为什么被折叠?



