继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

时间格式化

慕粉0202
关注TA
已关注
手记 9
粉丝 9
获赞 81
<!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>
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP