JavaScript วันที่ setFullYear ()
ตัวอย่าง 1
const d = วันที่ใหม่ ();
d.setFullYear(2020);
ความหมายและการใช้งาน
setFullYear()
กำหนดปีของวันที่
setFullYear()
สามารถตั้งเดือนและวันได้
ตัวอย่าง 2
const d = new Date();
d.setFullYear(2020, 10, 3);
ตัวอย่างที่ 3
ตั้งวันที่เป็นหกเดือนก่อน :
const d = new Date();
d.setFullYear(d.getFullYear(), d.getMonth() - 6);
รองรับเบราว์เซอร์
setFullYear()
เป็นคุณลักษณะ ECMAScript1 (ES1)
ES1 (JavaScript 1997) ได้รับการสนับสนุนอย่างสมบูรณ์ในเบราว์เซอร์ทั้งหมด:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
ไวยากรณ์
Date.setFullYear(year, month, day)
พารามิเตอร์
year | Required. The year. Negative values are allowed. |
month | Optional. The month (0 to 11). Higher and lower values are handeled with date maths:
|
day | Optional. The day (0 to 31). Higher and lower values are handeled with date maths:
|
คืนมูลค่า
หมายเลข. จำนวนมิลลิวินาทีระหว่างวันที่ถึงวันที่ 1 มกราคม 1970 00:00:00 UTC |