Detailed introduction to 13-digit timestamp in php+mysql

高洛峰
Release: 2023-03-06 20:34:02
Original
3300 people have browsed it
function getMillisecond() {
    list($t1, $t2) = explode(' ', microtime());
    // return $t2 . '.' .  ceil( ($t1 * 1000) );
    return $t2 . ceil( ($t1 * 1000) );
}
echo getMillisecond();
Copy after login

The above method can obtain the 13-digit timestamp and write it to the mysql table.

If the original time in the table is in date format. Just convert it like this.

Example: CU is a table. mtime is a field that holds a 13-digit timestamp. Time is the original writing time, in the format of datatime.

update CU set mtime = UNIX_TIMESTAMP(time)*1000;
Copy after login

Attachment:

Use function to convert UNIX timestamp to date: FROM_UNIXTIME()

select FROM_UNIXTIME(1156219870);

Function to convert date to UNIX timestamp: UNIX_TIMESTAMP()

Select UNIX_TIMESTAMP('2006-11-04 12:23:00′);

Example: mysql query the number of records on the day :

$sql=”select * from message Where DATE_FORMAT(FROM_UNIXTIME(chattime),'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y -%m-%d') order by id desc”;


Of course you can also choose to convert in PHP

UNIX timestamp conversion Use function for date: date()

date('Y-m-d H:i:s', 1156219870);

Use function to convert date to UNIX timestamp: strtotime ()

strtotime('2010-03-24 08:15:42');

The above is the detailed content of Detailed introduction to 13-digit timestamp in php+mysql. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template