如何将 JS 日期时间转换为 MySQL 日期时间?


借助 toISOString() 函数,我们可以将 JS 日期时间转换为 MySQL 日期时间。

我们来看一个 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...

更新于: 2020-06-27

1K+ 查看

启动您的 职业

通过完成课程获得认证

开始
广告