手册上的说明:
UNIX_TIMESTAMP()
, UNIX_TIMESTAMP(date
)
If called with no argument, returns a Unix timestamp (seconds since '1970-01-01 00:00:00'
UTC) as an unsigned integer. If UNIX_TIMESTAMP()
is called with a date
argument, it returns the value of the argument as seconds since '1970-01-01 00:00:00'
UTC. date
may be a DATE
string, a DATETIME
string, a TIMESTAMP
, or a number in the format YYMMDD
or YYYYMMDD
. The server interprets date
as a value in the current time zone and converts it to an internal value in UTC. Clients can set their time zone as described in Section 5.11.8, “MySQL Server Time Zone Support”.
这里的UNIX_TIMESTAMP()的返回值和C函数time(NULL)的返回值含义一样,
mysql> select UNIX_TIMESTAMP();
+------------------+
| UNIX_TIMESTAMP() |
+------------------+
| 1292815556 |
+------------------+
1 row in set
mysql> select FROM_UNIXTIME(1292815556);
+---------------------------+
| FROM_UNIXTIME(1292815556) |
+---------------------------+
| 2010-12-20 11:25:56 |
+---------------------------+
1 row in set