The method of converting JS timestamp to time format, and Apple compatibility issues

timestampToTime(timestamp) {

                //时间戳为10位需*1000,时间戳为13位的话不需乘1000

				// var date = new Date(timestamp * 1000); 

				var date = new Date(timestamp);
                
				const Y = date.getFullYear() + '-';

				const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';

				const D = date.getDate() + ' ';

				const h = date.getHours() + ':';

				const m = date.getMinutes() + ':';

				const s = date.getSeconds();

				return Y + M + D + h + m + s;

			},


// 使用示例   console.log(this.timestampToTime(1665633749075));  

Apple needs to be displayed in the form of '/', remember to change it:

const Y = date.getFullYear() + '/'

For example: 2022/10/13 15:47

const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '/';

Guess you like

Origin blog.csdn.net/ONLYSRY/article/details/127298857