JavaScript วันที่ setUTCMonth()
ตัวอย่าง
ตั้งเดือนเป็น 4 (พฤษภาคม):
const d = new Date();
d.setUTCMonth(4);
ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
เมธอด setUTCMonth() ตั้งค่าเดือน (จาก 0 ถึง 11) ของอ็อบเจ็กต์วันที่ตาม UTC
หมายเหตุ:มกราคมคือ 0 กุมภาพันธ์คือ 1 เป็นต้น
หมายเหตุ
UTC (Universal Time Coordinated) คือเวลาที่กำหนดโดยมาตรฐานเวลาโลก
เวลา UTC จะเหมือนกับเวลา GMT (เวลามาตรฐานกรีนิช)
รองรับเบราว์เซอร์
setUTCMonth()
เป็นคุณลักษณะ ECMAScript1 (ES1)
ES1 (JavaScript 1997) ได้รับการสนับสนุนอย่างสมบูรณ์ในเบราว์เซอร์ทั้งหมด:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
ไวยากรณ์
Date.setUTCMonth(month, day)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
month | Required. 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:
|
รายละเอียดทางเทคนิค
คืนมูลค่า: | ตัวเลข แทนจำนวนมิลลิวินาทีระหว่างวัตถุวันที่จนถึงเที่ยงคืน 1 มกราคม 1970 |
---|---|
เวอร์ชันจาวาสคริปต์: | ECMAScript 1 |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
ตั้งเดือนเป็น 4 (พฤษภาคม) และวันที่เป็น 20:
const d = new Date();
d.setUTCMonth(4, 20);
ตัวอย่าง
ตั้งวันที่เป็นวันสุดท้ายของเดือนที่แล้ว:
const d = new Date();
d.setUTCMonth(d.getUTCMonth(), 0);