js 将时间戳转换为年月日时分秒
点击转换按钮即可进行年月日的日期转换
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>js时间戳转年月日时分秒</title>
</head>
<body>
<button type="button" id="exchage" onclick="formDate()">转换</button>
<div id="innerHtml"></div>
</body>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
function formDate(){
var d = new Date();
var htm = d.getFullYear() + "年" + ('00'+(1+d.getMonth())).slice(-2) + '月' + ('00'+d.getDate()).slice(-2)+"日"+ " "+ ('00'+(d.getHours())).slice(-2) +":"+('00'+ (d.getMinutes())).slice(-2)+":"+('00'+(d.getSeconds())).slice(-2);
$('#innerHtml').html(htm);
}
</script>
</html>
效果: