将JavaScript日期时间转换为mySQL dateTime
,可以使用以下代码,可以使用以下代码:此代码以mySQL识别的格式生成一个dateTime字符串。将分钟添加到javascript dateTime:
date.setMinutes(date.getMinutes() minutesToAdd);
Passing to MySQL Datetime:
Once you have added the required number of minutes to the JavaScript Date object, you can convert it to a MySQL datetime string using the same code as shown in the first conversion step。
高级选项:var date; date = new Date(); date = date.getUTCFullYear() '-' ('00' (date.getUTCMonth() 1)).slice(-2) '-' ('00' date.getUTCDate()).slice(-2) ' ' ('00' date.getUTCHours()).slice(-2) ':' ('00' date.getUTCMinutes()).slice(-2) ':' ('00' date.getUTCSeconds()).slice(-2); console.log(date);对于更高级的用例,例如控制时区,请考虑使用MOMM.JS或FECHA之类的库。以下是示例:
// moment.js require('moment')()。格式('yyyy-mm-dd HH:mm:ss'); // FECHA require('fecha')。格式('yyyy-mm-dd hh:mm:ss');
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3