php+mysql中13位的时间戳详细介绍

php教程评论859 views阅读模式
function getMillisecond() {
    list($t1, $t2) = explode(' ', microtime());
    // return $t2 . '.' .  ceil( ($t1 * 1000) );
    return $t2 . ceil( ($t1 * 1000) );
}
echo getMillisecond();

上面方法就能获得13位的时间戳,写入到mysql表中。

如果原来在表中的时间是日期格式的。就这样转换一下。

举例:CU是一张表。mtime是字段,放13位时间戳的。time是原来写入的时间,格式为datatime的。

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

附:

UNIX时间戳转换为日期用函数: FROM_UNIXTIME()

select FROM_UNIXTIME(1156219870);

日期转换为UNIX时间戳用函数: UNIX_TIMESTAMP()

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

例:mysql查询当天的记录数:

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

当然大家也可以选择在PHP中进行转换

UNIX时间戳转换为日期用函数: date()

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

日期转换为UNIX时间戳用函数:strtotime()

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

以上就是php+mysql中13位的时间戳详细介绍的详细内容,更多请关注php教程网其它相关文章!

企鹅博客
  • 本文由 发表于 2020年10月3日 03:47:41
  • 转载请务必保留本文链接:https://www.qieseo.com/236739.html

发表评论