将MySQL时间戳转换为UNIX时间戳?
要将MySQL时间戳转换" title="时间戳转换">时间戳转换为UNIX时间戳,请使用UNIX_TIMESTAMP()。以下是语法-
select unix_timestamp(yourColumnName) from yourTableName;
让我们首先创建一个表-
mysql> create table DemoTable(Duetimestamp timestamp
);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(now());mysql> insert into DemoTable values('2016-01-21 12:34:00');
mysql> insert into DemoTable values('2018-05-01 02:00:00');
mysql> insert into DemoTable values('2017-03-02 01:10:20');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+---------------------+| Duetimestamp |
+---------------------+
| 2019-08-20 20:48:45 |
| 2016-01-21 12:34:00 |
| 2018-05-01 02:00:00 |
| 2017-03-02 01:10:20 |
+---------------------+
4 rows in set (0.00 sec)
以下是将MySQL时间戳转换为UNIX时间戳的查询-
mysql> select unix_timestamp(Duetimestamp) from DemoTable;
这将产生以下输出-
+------------------------------+| unix_timestamp(Duetimestamp) |
+------------------------------+
| 1566314325 |
| 1453359840 |
| 1525120200 |
| 1488397220 |
+------------------------------+
4 rows in set (0.04 sec)
以上是 将MySQL时间戳转换为UNIX时间戳? 的全部内容, 来源链接: utcz.com/z/334825.html