时间格式化
标签:
JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, width=device-width, maximum-scale=1, user-scalable=no">
<meta name="viewport" content="initial-scale=1.0,user-scalable=no,maximum-scale=1" media="(device-height: 568px)">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name='apple-touch-fullscreen' content='yes'>
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<meta name="format-detection" content="address=no">
<title>购物车</title>
<link href="css/base.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<script>
//获取当前时间戳的三种方法
var time1=Date.parse(new Date()); //1521884544000 毫秒不精确,毫秒是000显示
var time2=(new Date()).valueOf(); //1521884544653 第二种和第三种获取当前毫秒的时间戳
var time3=new Date().getTime(); //1521884544653
var time=new Date();
formatDate(time);
function formatDate(time){
var year=time.getFullYear();
var month=checkTime(time.getMonth()+1);
var day=checkTime(time.getDate());
var hours=checkTime(time.getHours());
var min=checkTime(time.getMinutes());
var sec=checkTime(time.getSeconds());
var date=year+'-'+month+'-'+day+'-'+hours+':'+min+':'+sec
document.write(date);
//小于10的时间前面+0
function checkTime(time){
if(time<10){
time= '0'+time
}
return time;
}
}
</script>
</body>
</html>
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦