• JS 日期格式化


    1、将中国标准时间格式化为(2017-06-06 15:05:04)

    function formatDateTime(theDate) {

    var _hour = theDate.getHours();

    var _minute = theDate.getMinutes();

    var _second = theDate.getSeconds();

    var _year = theDate.getFullYear()

    var _month = theDate.getMonth();

    var _date = theDate.getDate();

    if(_hour<10){_hour="0"+_hour ;}

    if(_minute<10){_minute="0"+_minute;  }

    if(_second<10){_second="0"+_second  }

    _month = _month + 1;

    if(_month < 10){_month = "0" + _month;}

    if(_date<10){_date="0"+_date  }

    return  _year + "-" + _month + "-" + _date + " " + _hour + ":" + _minute + ":" + _second ;

    }

    var time = new Date();

    var formatTime = formatDateTime(time );

    返回结果:

    Tue Jun 06 2017 15:31:09 GMT+0800 (中国标准时间)

    2017-06-06 15:31:09
    2、把格式化时间转换为毫秒数

    var formatTimeS = new Date('2017-06-06 15:31:09').getTime();

    返回结果:1496734269900

    3、把毫秒数转换为标准时间

    var formatTimeS = new Date(1496734269900);

    返回结果:

    Tue Jun 06 2017 15:31:09 GMT+0800 (中国标准时间)
    ---------------------
    作者:木雷双雄7
    来源:CSDN
    原文:https://blog.csdn.net/wlangmood/article/details/72879607
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    Ubuntu安装deb软件包错误(依赖关系问题)解决
    scrapy抓取的中文结果乱码解决办法
    删除Git记录里的大文件
    Ubuntu18.04 修改DNS
    linux实现ssh免密码登录
    Vim进阶指南
    查找相同图片并重命名
    Markdown进阶指南
    一眼看穿flatMap和map的区别
    Java8简明指南
  • 原文地址:https://www.cnblogs.com/CHWLearningNotes/p/10333156.html
Copyright © 2020-2023  润新知