ฟังก์ชัน getUTCSeconds() ของออบเจกต์ Date คืนค่า วินาที (0-59) ของวันที่กำหนดตามเวลาสากล (UTC)
ไวยากรณ์
dateObj.getUTCSeconds();
ตัวอย่าง
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var dateObj = new Date('september 26, 89 12:4:25:96'); document.write(dateObj.getUTCSeconds()); </script> </body> </html>
ผลลัพธ์
25
ตัวอย่าง: ไม่ระบุวินาที
หากไม่ระบุค่าวินาทีตอนสร้าง จะคืนค่า 0 ตามเวลา UTC
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var dateObj = new Date('september 26, 89 12:4'); document.write("วินาที: "+dateObj.getSeconds()); </script> </body> </html>
ผลลัพธ์
วินาที: 0
ตัวอย่าง: ใช้วันที่ปัจจุบัน
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var dateObj = new Date(); document.write("วินาที: "+dateObj.getUTCSeconds()); </script> </body> </html>
ผลลัพธ์
วินาที: 49
ตัวอย่าง: ค่าวินาทีเกินขอบเขต (0-59)
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var dateObj = new Date('september 26, 89 04:50:100'); document.write("มิลลิวินาทีปัจจุบัน: "+dateObj.getUTCSeconds()); </script> </body> </html>
ผลลัพธ์
มิลลิวินาทีปัจจุบัน: 0
สรุป:
- ช่วงค่า: 0-59
- ค่าเกินขอบเขตจะทำให้วันที่เลื่อนไป (แต่ getUTCSeconds() จะคืน 0 ในตัวอย่างนี้)
- ต่างจาก
getSeconds()ที่ใช้เวลาท้องถิ่น