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

js获取日期格式为年-月-日

2018-02-28 00:00 260 查看
var date = new Date();
var nowMonth = date.getMonth() + 1;
var strDate = date.getDate();
var seperator = "-";
if (nowMonth >= 1 && nowMonth <= 9) {
nowMonth = "0" + nowMonth;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var nowDate = date.getFullYear() + seperator + nowMonth + seperator + strDate;

参考:https://www.jianshu.com/p/3415c3aa722d
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: