首页 > Web开发 > 详细

js获取指定yyyy-mm格式的时间

时间:2019-09-15 19:04:22      阅读:632      评论:0      收藏:0      [点我收藏+]

1.获取当月时间格式: yyyy-MM

技术分享图片
getNowFormatDate() {//获取当月时间 yyyy-MM
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            if (month >= 1 && month <= 9) {
                month = ‘0‘ + month;
            }
            var currentdate = year + ‘-‘ + month
            return currentdate;
            //   console.log(currentdate) ;
}
View Code

技术分享图片

2.获取当月时间格式: yyyy-MM-dd

技术分享图片
function getNowFormatDate() {  //获取当月时间 yyyy-MM-dd
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
      month = ‘0‘ + month;
    }
    if (strDate >= 1 && strDate <= 9) {
      strDate = ‘0‘ + strDate ;
    }
    var currentdate = year + ‘-‘ + month + ‘-‘ + strDate
    return currentdate;
    // console.log(currentdate);
  }
View Code

技术分享图片

 

js获取指定yyyy-mm格式的时间

原文:https://www.cnblogs.com/mahmud/p/11523413.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!