Dùng toISOString() của JavaScript, cắt lấy 19 ký tự đầu và thay 'T' bằng khoảng trắng.
Ví dụ HTML/JS
<!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>
Kết quả
2018-11-23 11:14:38 Current Date is displayed above...
Định dạng YYYY-MM-DD HH:MM:SS tương thích với MySQL DATETIME.