เราสามารถแปลง JS date time เป็น MySQL datetime โดยใช้ฟังก์ชัน toISOString()
เรามาดูตัวอย่าง JavaScript
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<title>Web Page Design</title>
<script>
document.writeln(new Date().toISOString().slice(0, 19).replace('T', ' '));
</script>
</head>
<body>
<br>Current Date is displayed above...
</body>
</html> ผลลัพธ์
ต่อไปนี้เป็นผลลัพธ์
2018-11-23 11:14:38 Current Date is displayed above...