Home  >  Article  >  Database  >  What should I do if the numbers come out of mysql query time?

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

藏色散人
藏色散人Original
2020-11-13 09:59:122721browse

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 ? &#39;0&#39;+(date.getMonth()+1) : date.getMonth()+1) + &#39;/&#39;;
        D = date.getDate() + &#39; &#39;;
        h = date.getHours() + &#39;:&#39;;
        m = date.getMinutes() + &#39;:&#39;;
        s = date.getSeconds();
        return Y+M+D;
    }

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!

Statement:
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