1

我希望使用 将 a 转换为MySQL timestamp以秒为单位的纪元时间,PHP反之亦然。

最干净的方法是什么?

4

3 回答 3

6

See strtotime and date functions in PHP manual.

$unixTimestamp = strtotime($mysqlDate);
$mysqlDate = date('Y-m-d h:i:s', $unixTimestamp);
于 2008-09-22T15:27:38.873 回答
5

There are two functions in MySQL which are useful for converting back and forth from the unix epoch time that PHP likes:

from_unixtime()

unix_timestamp()

For example, to get it back in PHP unix time, you could do:

SELECT unix_timestamp(timestamp_col) FROM tbl WHERE ...
于 2008-09-22T15:27:03.243 回答
0

From MySQL timestamp to epoch seconds:

strtotime($mysql_timestamp);

From epoch seconds to MySQL timestamp:

$mysql_timestamp = date('Y-m-d H:i:s', time());
于 2008-09-22T15:27:57.423 回答