Home > Web Front-end > JS Tutorial > body text

js processing Json time with T time format (practical practice)

亚连
Release: 2018-05-18 14:46:03
Original
5771 people have browsed it

Summary of some practices for pit processing of json data passed from the background with T time format

new Date(data[j].addtime).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')

Only For this problem, you don’t need such a large amount of code to complete

Option 1 (applicable to China Standard Time):

var date = new Date(+new Date()+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'');
Copy after login

Option 2 (only used for the format conversion described in the title):

var date = new Date().toLocaleString().replace(/[年月]/g,'-').replace(/[日上下午]/g,'');
Copy after login

方案3(最准确但最麻烦,不推荐):

var date = new Date();  
var result = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds();
Copy after login

上面是我整理给大家的,希望今后会对大家有帮助。

相关文章:

详细为你解读tween.js是什么(图文教程)

 js中如何建立model数据模型(代码奉上,简单易懂)

如何在JS中实现打印的方式(结合代码详细解答)

The above is the detailed content of js processing Json time with T time format (practical practice). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template