利用三元运算符生成当前日期:年-月-日

        function getCurdate(){
            var myDate = new Date();
            var nowDateTime = myDate.getFullYear();
            nowDateTime = nowDateTime + ((myDate.getMonth() + 1) < 10 ? "-0" + (myDate.getMonth() + 1) : "-" + (myDate.getMonth() + 1));
            nowDateTime = nowDateTime + (myDate.getDate() < 10 ? "-0" + myDate.getDate() : "-" + myDate.getDate());
            return nowDateTime;
        }
        console.log(getCurdate());

参考:http://www.cnblogs.com/gilbert/p/5316393.html

posted @ 2016-03-24 17:59  奔跑的蜗牛~  阅读(331)  评论(0编辑  收藏  举报