您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

将JS日期时间转换为MySQL日期时间

将JS日期时间转换为MySQL日期时间

尽管JS确实拥有足够的基本工具来执行此操作,但它相当笨拙。

/**
 * You first need to create a formatting function to pad numbers to two digits…
 **/
function twoDigits(d) {
    if(0 <= d && d < 10) return "0" + d.toString();
    if(-10 < d && d < 0) return "-0" + (-1*d).toString();
    return d.toString();
}

/**
 * …and then create the method to output the date string as desired.
 * Some people hate using prototypes this way, but if you are going
 * to apply this to more than one Date object, having it as a prototype
 * makes sense.
 **/
Date.prototype.toMysqLFormat = function() {
    return this.getUTCFullYear() + "-" + twoDigits(1 + this.getUTCMonth()) + "-" + twoDigits(this.getUTCDate()) + " " + twoDigits(this.getUTCHours()) + ":" + twoDigits(this.getUTCMinutes()) + ":" + twoDigits(this.getUTCSeconds());
};
@H_301_5@
 

          

解决方法

有谁知道如何将JS dateTime转换为MySQL datetime?还有一种方法可以向JS日期时间添加特定的分钟数,然后将其传递给MySQL日期时间?

喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!

有谁知道如何将JS dateTime转换为MySQL datetime?还有一种方法可以向JS日期时间添加特定的分钟数,然后将其传递给MySQL日期时间?

MySQL 2022/1/1 18:17:28 有436人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶