JavaScript Đặt ngàyUTCFullYear()
Thêm ví dụ "Hãy tự mình thử" bên dưới.
Sự miêu tả
Phương thức setUTCFullYear() đặt năm của một đối tượng ngày, theo UTC.
Ghi chú
UTC (Giờ phối hợp quốc tế) là thời gian được thiết lập bởi Tiêu chuẩn giờ thế giới.
Giờ UTC giống với giờ GMT (Giờ chuẩn Greenwich).
Hỗ trợ trình duyệt
setUTCFullYear()
là một tính năng ECMAScript1 (ES1).
ES1 (JavaScript 1997) được hỗ trợ đầy đủ trên tất cả các trình duyệt:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
Cú pháp
Date .setUTCFullYear( year , month , day )
Giá trị tham số
Parameter | Description |
---|---|
year | Required. A value representing the year, negative values are allowed |
month | Optional. An integer representing the month
Expected values are 0-11, but other values are allowed:
|
day | Optional. An integer representing the day of month
Expected values are 1-31, but other values are allowed:
If the month has 31 days:
If the month has 30 days:
|
Giá trị trả về
Type | Description |
---|---|
Number | Milliseconds between the date object and midnight January 1 1970 |
Chi tiết kỹ thuật
Phiên bản JavaScript: | ECMAScript 1 |
---|
Thêm ví dụ
Ví dụ 2
Đặt ngày thành ngày 3 tháng 11 năm 2020, giờ UTC:
const d = new Date();
d.setUTCFullYear(2020, 10, 3);
Hãy tự mình thử »Ví dụ
Đặt ngày thành sáu tháng trước , giờ UTC:
const d = new Date();
d.setUTCFullYear(d.getUTCFullYear, d.getUTCMonth() - 6);
Hãy tự mình thử »