分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

JS 日期格式化

发布时间:2023-09-06 02:31责任编辑:熊小新关键词:暂无标签

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
版权声明:本文为博主原创文章,转载请附上博文链接!

JS 日期格式化

原文地址:https://www.cnblogs.com/CHWLearningNotes/p/10333156.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved