我有這個時間字符串如何在JavaScript中解析日期時間字符串的日期部分?
Tue, 20 Oct 2015 17:14:47 +0200
我需要從這個返回的日期部分。換句話說,從它得到date
,month
和year
。
目前我所做的:
pub_date = new Date("Tue, 20 Oct 2015 17:14:47 +0200")
day = pub_date.getDate()
month = pub_date.getMonth()
year = pub_date.getYear()
只有day
得到正確返回。 month
和year
返回錯誤結果。什麼會更正確?
什麼是不正確的結果你看到了嗎? – AtheistP3ace
當有疑問時...閱讀手冊https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date – charlietfl