如何將 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+ 檢視

啟動您的 職業

透過完成課程獲得認證

開始
廣告