您的位置:首页 > Web前端 > CSS

日期样式“yyyy-MM-dd”

2018-01-18 09:55 190 查看
   如何写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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  日期