The date format stored in the database is dated (YYYY-MM-DD format date) and datetime (YYYY-MM-DD 00:00:00 format date), when the date data in the database is passed to the front end with a Java program, if the background does not have a method to process the date, The long data is passed to the front end. For example:
Database stored on date: 2017-01-06 20:30:00
The date format for the front-end acquisition (interacting via Ajax) is: 1483705800000
The correct date format should be displayed on the front-end page.
The following is a JS method that converts a long to date or DateTime format:
return YYYY-MM-DD format Date (i):
function Dateformat_1 (longtypedate) {
var datetype = "";
var date = new Date ();
Date.settime (longtypedate);
Datetype + + date.getfullyear (); Year
Datetype = "-" + getmonth (date);//month
Datetype + = "-" + getday (date); Daily return
datetype;
}
Returns the month value
function getmonth (date) {
var month = "" of 01-12;
month = Date.getmonth () + 1; GetMonth () The resulting month is 0-11
if (month<10) {
month = "0" + month;
}
Return month;
}
Returns a date of 01-30
function getday (date) {
var day = "";
Day = Date.getdate ();
if (day<10) {Day
= ' 0 ' + day;
}
return day;
}
return YYYY-MM-DD format date (ii):
function Dateformat_2 (longtypedate) {
var datetype = "";
var date = new Date ();
Date.settime (longtypedate);
Datetype = date.getfullyear () + "-" +getmonth (date) + "-" +getday (date);//yyyy-mm-dd format date return
Datetype;
return YYYY-MM-DD 00:00:00 format date (i)
function Datetimeformat_1 (longtypedate) {var datetimetype = "";
var date = new Date ();
Date.settime (longtypedate); datetimetype+= date.getfullyear (); Year datetimetype+= "-" + getmonth (date); Month Datetimetype + = "-" + getday (date); Day datetimetype+= " " + getHours (date); When datetimetype+= ":" + getminutes (date); Minute datetimetype+= ":" + getseconds (date);
Separate return datetimetype;
//Returns the month Value function getmonth (date) {var month = "" of 01-12; month = Date.getmonth () + 1;
The month getmonth () is 0-11 if (month<10) {month = "0" + month;
Return month;
//Returns a date of 01-30 function getday (date) {var day = "";
Day = Date.getdate ();
if (day<10) {day = ' 0 ' + day;
Return day;
//Returns the Hour function getHours (date) {var hours = "";
Hours = Date.gethours ();
if (hours<10) {hours = "0" + hours;
} return hours;
//Returns the function getminutes (date) {var minute = "";
minute = Date.getminutes ();
if (minute<10) {minute = "0" + minute;
return minute;
//Returns the second function getseconds (date) {var second = "";
Second = Date.getseconds ();
if (second<10) {second = "0" + second;
return second; }
return YYYY-MM-DD 00:00:00 format date (ii)
function Datetimeformat_2 (longtypedate) {
var datetimetype = "";
var date = new Date ();
Date.settime (longtypedate);
Datetimetype = date.getfullyear () + "-" +getmonth (date) + "-" +getday (date) + " " +gethours (date) + ":" +getminutes (date) + ":" +getseconds (date);//yyyy-mm-dd 00:00:00 format date return
Datetimetype;
Call Method:
Datetimeformat_1 (1483705800000);
The results obtained are: 2017-01-06 20:30:00