微信小程序获取年月日时分

1,752 阅读1分钟
	//获取当天时间年月日时分秒
   		gettime() {
   			var timestamp = Date.parse(new Date());
   			var date = new Date(timestamp);
   			//获取年份  
   			var Y = date.getFullYear();
   			//获取月份  
   			var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
   			console.log(176,M)
   			//获取当日日期 
   			var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
   			//获取当日时
   			var H = date.getHours()<10?'0'+ date.getHours():date.getHours()
   			//获取当日分
   			var S = date.getMinutes()<10?'0'+ date.getMinutes():date.getMinutes()
   			this.startDate = Y + '-' + M + '-' + D
   			this.date = Y + '-' + M + '-' + D
   			this.hour = H + ':'+ S
   			this.time = H + ':'+ S
   			this.startYear = Y
   			console.log("当前时间:" + Y + '-' + M + '-' + D, this.startDate);
   		},