JavaScript Date.UTC()
ตัวอย่าง
รับจำนวนมิลลิวินาทีระหว่างวันที่ถึงวันที่ 1 มกราคม 1970:
let ms = Date.UTC(2020, 02, 30);
ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
Date.UTC() วิธีการส่งกลับจำนวนมิลลิวินาทีระหว่างวันที่ที่ระบุจนถึงเที่ยงคืนของวันที่ 1 มกราคม 1970 ตาม UTC
หมายเหตุ
UTC (Universal Time Coordinated) คือเวลาที่กำหนดโดยมาตรฐานเวลาโลก
เวลา UTC จะเหมือนกับเวลา GMT (เวลามาตรฐานกรีนิช)
รองรับเบราว์เซอร์
Date.UTC()
เป็นคุณลักษณะ ECMAScript1 (ES1)
ES1 (JavaScript 1997) ได้รับการสนับสนุนอย่างสมบูรณ์ในเบราว์เซอร์ทั้งหมด:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
ไวยากรณ์
Date.UTC(year, month, day, hours, minutes, seconds, millisec)
Date.UTC() เป็นวิธีการคงที่ของวัตถุ Date
คุณไม่สามารถใช้ในวันที่เช่น d.UTC()
ไวยากรณ์จะเป็น Date.UTC() เสมอ
ค่าพารามิเตอร์
Parameter | Description |
---|---|
year | Required. A four-digit value representing the year, negative values are allowed |
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:
|
hour | Optional. Default 0. An integer representing the hour.
Expected values are 0-23, but other values are allowed:
|
min | Optional. Default 0. An integer representing the minutes.
Expected values are 0-59, but other values are allowed:
|
sec | Optional. Default 0. An integer representing the seconds
Expected values are 0-59, but other values are allowed:
|
millisec | Optional. Default 0. An integer representing the milliseconds
Expected values are 0-999, but other values are allowed:
|
รายละเอียดทางเทคนิค
คืนมูลค่า: | ตัวเลข แทนจำนวนมิลลิวินาทีระหว่างวันที่-เวลาที่ระบุจนถึงเที่ยงคืน 1 มกราคม 1970 |
---|---|
เวอร์ชันจาวาสคริปต์: | ECMAScript 1 |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
สร้างวัตถุวันที่โดยใช้เวลา UTC แทนเวลาท้องถิ่น:
let d = new Date(Date.UTC(2020, 02, 30));