简体   繁体   中英

Converting the sql timestamp column to readable time and date in javascript

I am working with MySQL database. I am saving the time as a timestamp in the column. The problem is when I retrieve the time from that column I get the time stamp in a weird format. I want to get the time and data separately from the timestamp in JavaScript when I retrieve it.

Below is the time format I get

在此处输入图片说明

You can see the time format in the column I have retrieved , I don't know how to format it into my specified time.

"MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format." This is from mysql site. You can store only this type, but you can use one of the many time format functions to change it, when you need to display it.

For example, one of those functions is the DATE_FORMAT , which can be used to like so:

SELECT DATE_FORMAT(column_name, '%m/%d/%Y %H:%i') FROM tablename

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM