js Date 关于时间获取问题

时间:2023-03-09 00:38:35
js Date 关于时间获取问题
var date1 = new Date();

var timeFormat = {
'yyyy-mm-dd': date1 .toJSON().split('T')[0], //"2017-01-06T06:01:23.271Z" => [ "2017-01-06", "05:40:29.068Z" ] => "2017-01-06"
'stamp': date1*1,
'ch_date_time': date1.toLocaleFormat(), //"2017年1月6日 14:04:12",
'en_date‘:date1.toDateString(), //"Fri Jan 06 2017"
'yyyy/m/d':date1.toLocaleDateString(), //"2017/1/6"
''toTimeString
};

let _r = [];
$('#Conversion_getter+dl dt code').each(function(){
_r.push($(this).text().replace('()','').split('.').pop());
});
let _d = new Date();
_r.forEach((item, index)=>{
let txt = 'error'
try { txt = _d[item]()}
catch(e) {}
console.log(item, index,'=> ',txt)
})


toDateString 0 => Wed Jan 11 2017
toISOString 1 => 2017-01-11T13:17:52.079Z
toJSON 2 => 2017-01-11T13:17:52.079Z
toGMTString 3 => Wed, 11 Jan 2017 13:17:52 GMT
toLocaleDateString 4 => 2017/1/11
toLocaleFormat 5 => error
toLocaleString 6 => 2017/1/11 下午9:17:52
toLocaleTimeString 7 => 下午9:17:52
toSource 8 => error
toString 9 => Wed Jan 11 2017 21:17:52 GMT+0800 (中国标准时间)
toTimeString 10 => 21:17:52 GMT+0800 (中国标准时间)
toUTCString 11 => Wed, 11 Jan 2017 13:17:52 GMT
valueOf 12 => 1484140672079


MDN: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date