Home >Web Front-end >JS Tutorial >js processing Json time with T time format (practical practice)
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/,'');
Option 2 (only used for the format conversion described in the title):
var date = new Date().toLocaleString().replace(/[年月]/g,'-').replace(/[日上下午]/g,'');
方案3(最准确但最麻烦,不推荐):
var date = new Date(); var result = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds();
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
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!