The solution to mysql query time to get numbers: first query the digital time from the database; then use the “function timestampToTime(timestamp){…}” method in the front end to convert the timestamp to time.
Recommendation: “Mysql Video Tutorial”
The time of the database query is displayed as a string of numbers on the front end?
Solution:
I encountered a problem before, the time queried from the database was displayed as a number on the front end. The database I use is mysql, and my solution is to convert it at the front end. The code is as follows:
The string of numbers queried is a timestamp. You only need to convert the timestamp to time at the foreground. .
function timestampToTime(timestamp) { var date = new Date(timestamp);//If the timestamp is 10 digits, you need *1000, if the timestamp is 13 digits, you don’t need to multiply by 1000 Y = date.getFullYear() + '/'; M = (date.getMonth()+1 <10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '/' ; D = date.getDate() + ' '; h = date.getHours() + ':'; m = date.getMinutes() + ':'; s = date. getSeconds(); return Y+M+D; }
It should be noted that the query timestamp is 10 digits or 13 digits! ! !
The above is the detailed content of mysql query time and how to get the number. For more, please pay attention to other related articles on 1024programmer.com!