JS date转字符串(格式:yyyy-MM-dd HH:mm:ss)

/**
 * @description 将date转为字符串:yyyy-MM-dd HH:mm:ss格式
 * @author fzg
 */
export const formatDate = (date) => {
	var Y = date.getFullYear();
	var M = date.getMonth() + 1;
	var D = date.getDate();
	var hour = date.getHours();
	var minute = date.getMinutes();
	var second = date.getSeconds();
	return Y + '-' + (M < 10 ? ('0' + M) : M) + '-' + (D < 10 ? ('0' + D) : D) + ' ' + (hour < 10 ? ('0' + hour) :
		hour) + ':' + (minute < 10 ? ('0' + minute) : minute) + ':' + (second < 10 ? ('0' + second) : second);
}
posted @ 2023-01-05 11:37  合起来的彳亍  阅读(155)  评论(0编辑  收藏  举报