JavaScript Date setFullYear ()
ví dụ 1
const d = new Ngày ();
d.setFullYear (2020);
Định nghĩa và Cách sử dụng
setFullYear()
đặt năm của một ngày.
setFullYear()
cũng có thể đặt tháng và ngày.
Ví dụ 2
const d = new Date();
d.setFullYear(2020, 10, 3);
Ví dụ 3
Đặt ngày thành sáu tháng trước :
const d = new Date();
d.setFullYear(d.getFullYear(), d.getMonth() - 6);
Hỗ trợ trình duyệt
setFullYear()
là một tính năng ECMAScript1 (ES1).
ES1 (JavaScript 1997) được hỗ trợ đầy đủ trong tất cả các trình duyệt:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Cú pháp
Date.setFullYear(year, month, day)
Thông số
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:
|
Giá trị trả lại
Một số. Số mili giây giữa ngày và ngày 1 tháng 1 năm 1970 00:00:00 UTC. |