Home >Backend Development >PHP Tutorial >Detailed introduction to 13-digit timestamp in php+mysql
function getMillisecond() { list($t1, $t2) = explode(' ', microtime()); // return $t2 . '.' . ceil( ($t1 * 1000) ); return $t2 . ceil( ($t1 * 1000) ); } echo getMillisecond();
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;
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!