获取当前时间,不足补0

项目需求

word压缩成zip时,存放的路径格式为:url+当前时间+.zip
eg:var outpath = ‘/repository/system/fileservice/management/send_client_template/’+currentTime+".zip";
在这里插入图片描述
一、方法一

		function getNowFormatDate1() {
		     var date = new Date();
		     var year = date.getFullYear();
		     var month = date.getMonth() + 1;				//月
		     var dateDate = date.getDate();					//日
		     var dateHours = date.getHours();               //时
		     var dateMinutes = date.getMinutes();           //分
		     var dateSeconds = date.getSeconds();           //秒
		     if (month >= 1 && month <= 9)  month = "0" + month;
		     if (dateDate >= 0 && dateDate <= 9)  dateDate = "0" + dateDate;
		     if(dateHours >= 0 && dateHours <= 9) dateHours="0" + dateHours;
		     if(dateMinutes >= 0 && dateMinutes <= 9) dateMinutes="0" + dateMinutes;
		     if(dateSeconds >= 0 && dateSeconds <= 9) dateSeconds="0" + dateSeconds;
		     var currentdate = year + month + dateDate + dateHours + dateMinutes + dateSeconds;
		     return currentdate;
		};

二、方法二

		function getNowFormatDate2() {
		     var date = new Date();
		     var year = date.getFullYear().toString();
		     var month = (date.getMonth() + 1).toString();
		     var dateDate = date.getDate().toString();
		     var dateHours = date.getHours().toString();               //时
		     var dateMinutes = date.getMinutes().toString();           //分
		     var dateSeconds = date.getSeconds().toString();           //秒
			 function timeAdd0(m) {
			    if(m.length<=1){
			        m='0'+m;
			    }
			    return m
			 } 
			year=timeAdd0(year)
			month=timeAdd0(month)
			dateDate=timeAdd0(dateDate)
			dateHours=timeAdd0(dateHours)
			dateMinutes=timeAdd0(dateMinutes)
			dateSeconds=timeAdd0(dateSeconds)			
			console.log(year+"-"+month +"-"+dateDate +" "+dateHours+":"+dateMinutes+":"+dateSeconds)	//2020-01-16 18:58:21
		};	
发布了1 篇原创文章 · 获赞 0 · 访问量 28
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览