When the page is initialized, use JavaScript to format the date type read from the database into the desired type. Format it as yyyy year MM month dd day HH hour mm minute ss second. You can refer to the code and play freely.
The code is as follows:
//传入从数据库中取出的日期类型数据 function getformat date (d){ var formate_date time ; var array = d.split(" "); var date = array[0]; var time = array[1]; var array_date = date.split("-"); var array_time = time.split(":"); var second = array_time[2].split(".")[0]; formate_datetime = array_date[0] + "年" + removeZero(array_date[1]) + "月" + removeZero(array_date[2]) + "日 " + removeZero(array_time[0]) + "时" + removeZero(array_time[1]) + "分" + second + "秒"; return formate_datetime; } //去掉月、日、时、分前的0 function removeZero(data) { if(data.charAt(0) == "0"){ return data.charAt(1); } else { return data; } }
The above is the detailed content of How to use JS to format the date type read from the database into the desired type. For more information, please follow other related articles on the PHP Chinese website!