欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

将时间20180616142525换算为时间戳

程序员文章站 2022-05-02 15:14:25
...

1.html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}	
			
		</style>
	</head>
	<body>
		<div>20180616142525</div>
		<div class="time"></div>
		<script src="https://cdn.bootcss.com/jquery/1.8.3/jquery.js" type="text/javascript" charset="utf-8"></script>
		
		<script type="text/javascript"> 
			/*事件转为时间戳*/
			function timeZhuan(aa) {
			  var string_year = aa.substring(0, 4);
			  var string_month = aa.substring(4, 6);
			  var string_day = aa.substring(6, 8);
			  var string_hour = aa.substring(8, 10);
			  var string_minute = aa.substring(10, 12);
			  var string_second = aa.substring(12, 14);
			  var bb = new Date(string_year, (string_month - 1), string_day, string_hour, string_minute, string_second);
			  return bb;
			}
			
			var time='20180616142525';
			
			time=timeZhuan(time);
			/*函数返回时间*/
			console.log(time);
			/*转为时间戳的时间*/
			console.log(time.valueOf());
			
			$(".time").html(time.valueOf());
			
		</script> 
	</body>
</html>

2.效果

将时间20180616142525换算为时间戳

相关标签: 时间转时间戳