亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在線等!為什么 JS 中的 new Date("0") 返回的是2000年,而不是1970年?謝謝哈~

在線等!為什么 JS 中的 new Date("0") 返回的是2000年,而不是1970年?謝謝哈~

MMTTMM 2019-09-09 20:29:12
console.log(newDate(0));VM655237:1ThuJan01197008:00:00GMT+0800(中國標準時間)console.log(newDate("0"));VM655252:1SatJan01200000:00:00GMT+0800(中國標準時間)
查看完整描述

2 回答

?
夢里花落0921

TA貢獻1772條經驗 獲得超6個贊

參數是字符串的時候,會使用Date.parse,而其中咋解釋字符串"0"是實現自己定義的。這與參數是數字的時候完全不同。
TheparsefunctionappliestheToStringoperatortoitsargument.IfToStringresultsinanabruptcompletiontheCompletionRecordisimmediatelyreturned.Otherwise,parseinterpretstheresultingStringasadateandtime;itreturnsaNumber,theUTCtimevaluecorrespondingtothedateandtime.TheStringmaybeinterpretedasalocaltime,aUTCtime,oratimeinsomeothertimezone,dependingonthecontentsoftheString.ThefunctionfirstattemptstoparsetheStringaccordingtotheformatdescribedinDateTimeStringFormat(20.3.1.15),includingexpandedyears.IftheStringdoesnotconformtothatformatthefunctionmayfallbacktoanyimplementation-specificheuristicsorimplementation-specificdateformats.Stringsthatareunrecognizableorcontainout-of-boundsformatfieldvaluesshallcauseDate.parsetoreturnNaN.
                            
查看完整回答
反對 回復 2019-09-09
  • 2 回答
  • 0 關注
  • 346 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號