1024programmer Mysql What should I do if the mysql query time comes out with numbers?

What should I do if the mysql query time comes out with numbers?

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!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/what-should-i-do-if-the-mysql-query-time-comes-out-with-numbers/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索