js获取某天日期

发布时间:2023年12月31日

获取某天日期

getSomeDay(someDay) {
	let currentDate = new Date();
	let targetday_milliseconds = currentDate.getTime() + 1000 * 60 * 60 * 24 * someDay;
	currentDate.setTime(targetday_milliseconds);

	const doHandleMonth = (month) => {
		let m = month;
		if (month.toString().length == 1) {
			m = `0${month}`
		}
		return m
	}

	let year = currentDate.getFullYear();
	let month = currentDate.getMonth();
	let date = currentDate.getDate();
	let day = currentDate.getDay();
	let time = parseInt(currentDate.getTime() / 1000);
	month = doHandleMonth(month + 1);
	date = doHandleMonth(date);

	const week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
	return {
		't': time,
		'y': year,
		'm': month,
		'd': date,
		'w': week[day]
	};
}
文章来源:https://blog.csdn.net/Smile_ping/article/details/135320043
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。