تعيين تاريخ جافا سكريبت
مثال
ضبط العام على 2015:
const d = new Date();
d.setUTCFullYear(2015);
المزيد من الأمثلة "جربها بنفسك" أدناه.
التعريف والاستخدام
تحدد طريقة setUTCFullYear () سنة كائن التاريخ ، وفقًا للتوقيت العالمي المنسق (UTC).
ملحوظات
UTC (تنسيق التوقيت العالمي) هو الوقت الذي يحدده معيار التوقيت العالمي.
التوقيت العالمي المنسق (UTC) هو نفس توقيت غرينتش (توقيت غرينتش).
دعم المتصفح
setUTCFullYear()
هي إحدى ميزات ECMAScript1 (ES1).
ES1 (JavaScript 1997) مدعوم بالكامل في جميع المتصفحات:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
بناء الجملة
Date.setUTCFullYear(year, month, day)
قيمه المعامل
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:
|
قيمة الإرجاع
Type | Description |
---|---|
Number | Milliseconds between the date object and midnight January 1 1970 |
تفاصيل تقنية
إصدار JavaScript: | ECMAScript 1 |
---|
مزيد من الأمثلة
مثال 2
اضبط التاريخ على 3 نوفمبر 2020 ، بتوقيت UTC:
const d = new Date();
d.setUTCFullYear(2020, 10, 3);
مثال
اضبط التاريخ على ستة أشهر مضت ، بالتوقيت العالمي المنسق:
const d = new Date();
d.setUTCFullYear(d.getUTCFullYear, d.getUTCMonth() - 6);