uni-app系统时间与时间戳之间的相互转换

1. 系统时间格式转换成自定义格式

getDate(type) {
	// 获取当前系统时间
	let date = new Date();
	
	let year = date.getFullYear();
	let month = date.getMonth() + 1;
	let day = date.getDate();
				
	month = month > 9 ? month : '0' + month;;
	day = day > 9 ? day : '0' + day;
	return `${year}-${month}-${day}`;
},

2. 获取当前时间的后一天

getDate(type) {
	// 获取当前时间
	let date = new Date();
	// 当前时间转换为时间戳(13位,不足13位要*1000)
	date = date.getTime();
	// 在当前时间戳数据基础上加上一天的时间戳数据(我之前在网上搜了一天的时间戳是86400,怎么转换都是当天,后面才发现没有*1000,*1000是精确到毫秒)
	date = date  + 86400000;
	// 将操作后的时间戳转换为系统时间格式		
	let dateInfo = new Date(date);

	// 将系统时间格式转换为自定义时间格式
	let year = dateInfo.getFullYear();
	let month = dateInfo.getMonth() + 1;
	let day = dateInfo.getDate();
	
	month = month > 9 ? month : '0' + month;;
	day = day > 9 ? day : '0' + day;
	return `${year}-${month}-${day}`;
},

你可能感兴趣的:(uni-app)