JavaScript获取时间展示 xxxx-xx-xx xx:xx:xx

 // 获取当前时间
      GetCurrentTime(){
        let date=new Date(),
            year=date.getFullYear(),
            month=date.getMonth(),
            day=date.getDate(),
            hour=date.getHours(),
            miute=date.getMinutes(),
            second=date.getSeconds();

                 month>=10? month=month+1:month=`0${month+1}`;
                 day>=10? day=day:day=`0${day}`;
                 hour>=10? hour=hour:hour=`0${hour}`;
                 miute>=10? miute=miute:miute=`0${miute}`;
                 second>=10? second=second:second=`0${second}`;
            //xxxx年-x月-x日
            this.dataForm.visitTime = `${year}-${month}-${day} ${hour}:${miute}:${second}`;   
      },

你可能感兴趣的:(javascript,开发语言,ecmascript)