What should I do if the numbers come out of mysql query time?

藏色散人
Release: 2021-04-23 09:02:36
Original
2652 people have browsed it

The solution for mysql query time to get the digital time: first query the digital time from the database; then use the "function timestampToTime(timestamp){...}" method in the front end to convert the timestamp into time.

What should I do if the numbers come out of mysql query time?

Recommendation: "mysql video tutorial"

The time queried from the database is displayed as a string of numbers on the front end ?

Solution:

I encountered a problem before, and the time queried from the database was displayed as a number on the front end. The database I use is mysql. My solution is to convert it on the front end. The code is as follows:

The string of numbers queried is a timestamp. I only need to convert the timestamp into time in the frontend.

function timestampToTime(timestamp) { var date = new Date(timestamp);//时间戳为10位需*1000,时间戳为13位的话不需乘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; }
Copy after login

It should be noted that the timestamp queried is 10 digits or 13 digits! ! !

The above is the detailed content of What should I do if the numbers come out of mysql query time?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!