在 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)
在上面的查詢中,它同時使用了日期和時間格式字串。
廣告