美文网首页
时间戳转换成年月日时分秒格式

时间戳转换成年月日时分秒格式

作者: 素时年锦 | 来源:发表于2018-01-18 17:48 被阅读0次
   function getNowFormatDate() {
        var date = new Date();         //获取时间
        var year = date.getFullYear();  //年
        var month = date.getMonth() + 1; //月
        var strDate = date.getDate();   //日
        var hours = date.getHours();    //时
        var minutes = date.getMinutes(); //分
        var second = date.getSeconds(); //秒

        //判断时间的
        // if (month >= 1 && month <= 9) {
        //     month = "0" + month;
        // }
        // if (strDate >= 0 && strDate <= 9) {
        //     strDate = "0" + strDate;
        // }
        // if(hours >= 0 && hours <= 9){
        //     hours = "0" + hours;
        // }
        // if(minutes >= 0 && minutes <= 9){
        //     minutes = "0" + minutes;
        // }
        // if(second >= 0 && second <= 9){
        //     second = "0" + second;
        // }
        //三元表达式优化

        var currentdate = year +'-'+ 
        (month>9? month : '0'+month)  +'-'+ 
        (strDate>9? strDate : '0'+strDate) +' '+ 
        (hours>9? hours : '0'+hours) +':'+
        (minutes>9? minutes : '0'+minutes) +':'+ 
        (second>9? second : '0'+second) ;

        console.log(currentdate)
        return currentdate;
    }
    getNowFormatDate()

相关文章

  • 4.时间的处理,monent插件

    1.格式化时间 2.格式化年月日时分秒 3.通过获取当前时间的时间戳转化为年月日时分秒 4.某个时间时间戳转换成日...

  • datetime:时间戳转换

    将时间戳转换为年月日时分秒格式: 将年月日时分秒格式转换为时间戳:

  • js 时间格式化

    dateTime=====>要格式化的数据(包括:时间戳,年月日时分秒...) fmt===>要格式化的格式(y:...

  • 格式化时间方法

    /** *时间戳转化为年月日时分秒 *number:传入时间戳 *format:返回格式,支持自定义,但参数必须...

  • HIVE中的from_unixtime函数

    hive中的from_unixtime()函数,可以把时间戳格式的时间,转化为年月日时分秒格式的时间。 from_...

  • jquery将时间戳转为精确到秒的时间

    时间戳 转为年月日 时分秒 时间转为时间戳,或时间戳转为时间

  • UTC时间与时区时间转换

    描述 时间日期与time stamp转换 参考 C语言实现将时间戳转换为年月日时分秒和将年月日时分秒转换为时间戳 ...

  • 【微信小程序】时间戳转换

    本章主要讲时间戳转换成时间,Y/M/D h:m:s(年月日时分秒) 将js代码放到utils文件的utils.js...

  • day19时间模块

    时间模块 主要包含处理年月日时分秒对应的时间(着重时分秒) 专门处理年月日 1.获取当前时间 时间戳:就是从格林威...

  • CocosCreator3.x开发笔记3:时间相关

    秒转换为时分秒 获取时间戳 number转年月日

网友评论

      本文标题:时间戳转换成年月日时分秒格式

      本文链接:https://www.haomeiwen.com/subject/yziwoxtx.html