MySQL 如何使用FROM_UNIXTIME()函数进行格式化输出
如果我们想要从FROM_UNIXIME()函数中以特定的格式输出结果,我们可以在其中使用日期格式字符串、时间格式字符串或两者都使用。以下是使用格式字符串在FROM_UNIXTIME()函数中进行格式化的示例 −
mysql> Select FROM_UNIXTIME(1555033470 '%Y %M %D')AS 'Formatted Output';
+------------------+
| Formatted Output |
+------------------+
| 2019 April 12th |
+------------------+
1 row in set (0.00 sec)
在上面的查询中,只使用了日期格式字符串。
mysql> Select FROM_UNIXTIME(1555033470 '%h:%i:%s')AS 'Formatted Output';
+------------------+
| Formatted Output |
+------------------+
| 07:14:30 |
+------------------+
1 row in set (0.00 sec)
在上面的查询中,只使用了时间格式字符串。
mysql> Select FROM_UNIXTIME(1555033470, '%Y %M %D %h:%i:%s')AS 'Formatted Output';
+--------------------------+
| Formatted Output |
+--------------------------+
| 2019 April 12th 07:14:30 |
+--------------------------+
1 row in set (0.00 sec)
在上面的查询中,同时使用日期和时间格式字符串。
阅读更多:MySQL 教程
极客教程