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

转载于:https://www.cnblogs.com/so-letitgo/p/6256126.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值