为简单起见,我建议使用 MySQL 的时间戳字段。因为数据库会理解它是什么,所以它的存储效率比您的文本版本(作为数字,而不是字符串)要高效得多,您可以用它做更多的事情。
例如:
mysql> CREATE TABLE foo (something TEXT NOT NULL, created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP);
Query OK, 0 rows affected (0.11 sec)
mysql> INSERT INTO foo (something) VALUES ("one");
Query OK, 1 row affected (0.07 sec)
mysql> INSERT INTO foo (something) VALUES ("two");
Query OK, 1 row affected (0.13 sec)
mysql> SELECT * FROM foo;
+-----------+---------------------+
| something | created |
+-----------+---------------------+
| one | 2013-09-18 22:57:01 |
| two | 2013-09-18 22:57:03 |
+-----------+---------------------+
2 rows in set (0.00 sec)
mysql> SELECT something, NOW() - created as seconds_since_insert FROM foo;
+-----------+----------------------+
| something | seconds_since_insert |
+-----------+----------------------+
| one | 136 |
| two | 134 |
+-----------+----------------------+
2 rows in set (0.00 sec)