ฟังก์ชัน toUTCString() ของออบเจกต์ Date คืนค่า สตริงวันที่-เวลาในรูปแบบ UTC (GMT)
ไวยากรณ์
dateObj.toUTCString()
ตัวอย่าง
<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.toUTCString()); </script> </body> </html>
ผลลัพธ์
เวลาปัจจุบัน: Tue, 26 Sep 1989 06:34:25 GMT
ตัวอย่าง: ใช้วันที่ปัจจุบัน
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var dateObj = new Date(); document.write("เวลาปัจจุบัน: "+dateObj.toUTCString()); </script> </body> </html>
ผลลัพธ์
เวลาปัจจุบัน: Thu, 18 Oct 2018 08:14:32 GMT
รูปแบบผลลัพธ์ (RFC 7231 / RFC 2822):
Day, DD Mon YYYY HH:MM:SS GMT
- วันสัปดาห์ย่อ 3 ตัวอักษร
- วันที่ 2 หลัก
- เดือนย่อ 3 ตัวอักษร
- ปี 4 หลัก
- เวลา 24 ชั่วโมง
- เสมอ
GMT(UTC)
การใช้งานทั่วไป:
- HTTP Headers (Date, Expires, Last-Modified)
- Cookie expiration date
- Logging ที่ต้องการเวลามาตรฐานสากล
- ต่างจาก
toISOString()ที่เป็น ISO 8601 format