简体   繁体   English

如何获取JSX输入字段的值到Javascript日期对象,然后将其插入到mysql YYYY-MM-DD格式?

[英]How to get value of JSX Input field to Javascript date object and then insert it to mysql YYYY-MM-DD format?

I need to get the picked value of input type= "date" to a Javascript Date object and format it, then use Insert Into Table for MySQL. 我需要将输入类型=“日期”的选取值添加到Javascript Date对象并对其进行格式化,然后使用Insert Into Table for MySQL。 How? 怎么样?

I need to get the picked date value from input to use with this function, and after that I need a function that inserts that picked value to MySQL. 我需要从输入中获取选择的日期值以使用此函数,之后我需要一个将选择的值插入MySQL的函数。 I don't know how to do those steps.. I am making a rental system, so I will have two inputs "startdate" "enddate" that need to be converted for inserting to database. 我不知道如何做这些步骤..我正在制作一个租赁系统,所以我将有两个输入“startdate”“enddate”,需要转换为插入数据库。

This is a function I found that formats a date: 这是我发现的格式化日期的函数:

(function() {
    Date.prototype.toYMD = Date_toYMD;
    function Date_toYMD() {
        var year, month, day;
        year = String(this.getFullYear());
        month = String(this.getMonth() + 1);
        if (month.length == 1) {
            month = "0" + month;
        }
        day = String(this.getDate());
        if (day.length == 1) {
            day = "0" + day;
        }
        return year + "-" + month + "-" + day;
    }
})();

This might be helpful for you. 这可能对你有所帮助。

function getYYMMDD() {
   var now = new Date();     
   var mm = (now.getMonth() + 1).toString().padStart(2,"0");
   var yyyy = now.getFullYear().toString();
   var dd =  now.getDate().toString().padStart(2,"0");
   var date = [yyyy, mm, dd].join("-");
   return date;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在核心 JavaScript 中将新日期 object 格式化为 MySQL 格式 YYYY-MM-DD hh-mm-ss? - How to format new date object to MySQL format YYYY-MM-DD hh-mm-ss in core JavaScript? 格式 JavaScript 日期为 yyyy-mm-dd - Format JavaScript date as yyyy-mm-dd 将 javascript 到日期对象转换为 mysql 日期格式 (YYYY-MM-DD) - Convert javascript to date object to mysql date format (YYYY-MM-DD) 如何在javascript中为输入字段编写mm / dd / yyyy日期格式? - how to write mm/dd/yyyy date format for input field in javascript? JavaScript日期对象因格式而异:yyyy-mm-dd与mm-dd-yyyy - Javascript Date object different depending on format: yyyy-mm-dd vs mm-dd-yyyy 如何获取 YYYY-MM-DD 格式的日期? - How do I get a date in YYYY-MM-DD format? 如何将 yyyy-mm-dd 格式的字符串转换为 Javascript 日期 Object 而不将日期视为 UTC - How to convert a string in yyyy-mm-dd format to a Javascript Date Object without considering the date as UTC 我如何以格式(YYYY-MM-DD)获取时刻格式日期选择器的值 - how can i get value of moment format date picker in format (YYYY-MM-DD) 如何在提交时将输入日期格式从 MM dd yy 更改/转换为 yyyy-mm-dd - How to change/convert input date format from MM dd yy to yyyy-mm-dd on submit 日期选择器和日期字段中的日期格式(YYYY-MM-DD) - Date Format(YYYY-MM-DD) in DatePicker and Date field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM