moment.js 的简单应用

 moment.js :时间处理的组件

例子:moment.html

<!DOCTYPE html>
<html>
<head>
    <title>moment.js</title>
    <meta charset="utf-8">
     <script type="text/javascript" src="jquery.min.js"></script>
<script src="moment.min.js"></script>

</head>
<body>
hi, I am moment.
以下是时间:
    <div class="www">
        
    </div>
<script >
        
            $('.www').html(moment().format());           
        
         //亦可
        // function a(){
        //     $('.www').html(moment().format());           
        // }
        // a();
</script>
</body>

</html>

 

简单了解常用的用法。比如:

1)能把日期以常见的格式展示 如2016年5月3号  2016年05月03号 2016年05月03号 3时;

2)能获取两个时间的时间差,差的 年、月、日、时、分、秒;

3)当前时间往前100个小时是什么时间,往后100个小时是什么时间;

 

 

原文地址:https://www.cnblogs.com/shenxiaolin/p/6076046.html