当前位置:网站首页>JS converts timestamp to normal time format

JS converts timestamp to normal time format

2022-06-10 12:16:00 000000001111

<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>js Convert timestamp to normal time format </title>
	</head>
	<body>

	</body>
	<script type="text/javascript">
		//  Method 1 
		function timestampTime(timestamp) {
    
			var date = new Date(timestamp * 1000); // Timestamp 10 Bitwise demand *1000, Timestamp 13 You don't need to take a seat 1000
			var Y = date.getFullYear() + '-';
			var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
			var D = date.getDate() + ' ';
			var h = date.getHours() + ':';
			var m = date.getMinutes() + ':';
			var s = date.getSeconds();
			return Y + M + D + h + m + s;
		}
		var time = timestampTime(1177824835);
		console.log(time);	//2007-04-29 13:33:55
		
		//  Method 2 
		var time = new Date(parseInt(1177824835) * 1000).toLocaleString().replace(/:\d{
    1,2}$/,' ');
		console.log(time);	//2007/4/29  Afternoon 1:33 
		
	</script>
</html>

 Insert picture description here

原网站

版权声明
本文为[000000001111]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101155031510.html