[英]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.