Sow nothing reap nothing

JQ获取当前时间(年/月/日 时:分:秒)

已有1,775次关注

1、效果截图:
QQ截图20210114104252.png

2、HTML/JQ代码:

<!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>jQuery获取当前时间(年/月/日 时:分:秒)</title>
</head>
<body>
<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    function getNowDateTime(){
        var now = new Date(); 
        var year = now.getFullYear(); 
        var month = (now.getMonth() + 1) < 10 ? '0' + (now.getMonth() + 1) : now.getMonth() + 1; 
        var dates = now.getDate() < 10 ? '0' + now.getDate() : now.getDate();
        var hours = now.getHours() < 10 ? "0" + now.getHours() : now.getHours();
        var minutes = now.getMinutes() < 10 ? '0' + now.getMinutes() : now.getMinutes();
        var seconds = now.getSeconds() < 10 ? '0' + now.getSeconds() : now.getSeconds();
        return year + "/" + month + "/" + dates + " " + hours + ":" + minutes + ":" + seconds; 
    }
    $(function(){
        console.log(getNowDateTime());
    })
</script>
</html>

已自动关闭评论