JS 构造函数 Date

<script src="https://cdn.bootcss.com/moment.js/2.24.0/moment.js"></script>
    <script type="text/javascript">
    
        var d1 = new Date();
        var result = d1.toString();
        console.log(result);    //Wed Aug 28 2019 14:39:05 GMT+0800 (中国标准时间)


        var d1 = new Date();
        var result = d1.toLocaleString();
        console.log(result);    //2019/8/28 下午2:39:05

        
        var d1 = new Date();
        var result = d1.getTime();
        console.log(result);    //时间戳        1566974345508


        var d1 = new Date(1568974098332);
        var result = d1.toLocaleString();
        console.log(result);    //2019/9/20 下午6:08:18


        //引用第三方JS资源库实现日期输出
        var d1 = new Date();
        
        //Format Dates
        var result1 =moment().format("YYYY-MM-DD,h:mm:ss a");
        var result2 = moment().format("YYYY/MM/DD");
        var result3 = moment().format("dddd");
        var result4 = moment().format("MM-Do-YY");
        var result5 = moment().format("YYYY [escaped] YYYY");

        console.log("",result1);    //2019-08-29,9:26:32 am
        console.log("",result2);    //2019/08/29
        console.log("",result3);    //Thursday
        console.log("",result4);    //2019-08-29,9:26:32 am
        console.log("",result5);    //2019 escaped 2019

        //Relative Time
        var fhz1 = moment("2011 01 24","YYYY MM DD").fromNow();
        var fhz2 = moment("2031 11 04","YYYY MM DD").fromNow();
        var fhz3 = moment().startOf("day").fromNow();
        var fhz4 = moment().endOf("day").fromNow();
        var fhz5 = moment().startOf("hour").fromNow();
        var fhz6 = moment().endOf("hour").fromNow();

        console.log("",fhz1);    //9 years ago
        console.log("",fhz2);    //in 12 years
        console.log("",fhz3);    //10 hours ago
        console.log("",fhz4);    //in 14 hours
        console.log("",fhz5);    //40 minutes ago
        console.log("",fhz6);    //in 20 minutes

        //Calendar Time
        var jg1 = moment().subtract(2, 'days').calendar();
        var jg2 = moment().subtract(31, 'days').calendar();
        var jg3 = moment().subtract(18, 'days').calendar();
        var jg4 = moment().subtract(29, 'days').calendar();
        var jg5 = moment().calendar();
        var jg6 = moment().add(1,"days").calendar();
        var jg7 = moment().add(5,"days").calendar();
        var jg8 = moment().add(23,"days").calendar();
        
        console.log("",jg1);        //Last Tuesday at 9:49 AM
        console.log("",jg2);        //07/29/2019
        console.log("",jg3);        //08/11/2019        
        console.log("",jg4);        //07/31/2019        
        console.log("",jg5);        //Today at 9:49 AM        
        console.log("",jg6);        //Tomorrow at 9:49 AM
        console.log("",jg7);        //Tuesday at 9:49 AM
        console.log("",jg8);        //09/21/2019
        
        //Multiple Locale Support
        var fh1 = moment.locale();
        var fh2 = moment().format('LT');
        var fh3 = moment().format('LTS');
        var fh4 = moment().format('L');
        var fh5 = moment().format('l');
        var fh6 = moment().format('LL');
        var fh7 = moment().format('ll');
        var fh8 = moment().format('LLL');
        var fh9 = moment().format('lll');
        var fh10 = moment().format('LLLL');
        var fh11 = moment().format('llll');
        
        console.log("",fh1);    //en
        console.log("",fh2);    //2:32 PM
        console.log("",fh3);    //2:32:28 PM
        console.log("",fh4);    // 08/29/2019
        console.log("",fh5);    //8/29/2019
        console.log("",fh6);    // August 29, 2019
        console.log("",fh7);    //Aug 29, 2019
        console.log("",fh8);    //August 29, 2019 2:34 PM
        console.log("",fh9);    // Aug 29, 2019 2:35 PM
        console.log("",fh10);    //Thursday, August 29, 2019 2:32 PM
        console.log("十一",fh11);    //Thu, Aug 29, 2019 2:35 PM
        
        
        
    </script>

 

转载于:https://www.cnblogs.com/lidyfamily/p/11429636.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值