js时间格式转换 ╰+哭是因爲堅強的太久メ 2022-01-10 01:29 263阅读 0赞 存在mysql数据库中的时间字段,读取出来后格式变为了:2019-06-05T16:00:00.000+0000 想要显示为正常的日期格式:年月日时分秒,js代码如下: <!DOCTYPE html> <html xmlns:th="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8"> <title>首页</title> <script src="js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script> </head> <body> <script type="text/javascript"> var value = '2019-06-05T16:00:00.000+0000'; var time = timeFommater(value); console.log(time); function timeFommater(value) { var dateee = new Date(value).toJSON(); var date = new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '') return date; } </script> </body> </html> 转换后的结果为:2019-06-06 00:00:00 实验结果如图: ![20190620204406528.png][] [20190620204406528.png]: /images/20220109/41d14d7c16e24abd94be1254b108500f.png
还没有评论,来说两句吧...