摘要:
在MySQL数据库中对日期函数进行格式化输出时,关于小时的输出有”H”和”h”两种不同的写法,那么它们有什么不同呢?
下文将一一道来
H 和 h输出的说明
Date_FORMAT 中如果采用大写的H,则会输出24小时制的时间信息;
Date_FORMAT 中如果采用小写的h,则会输出12小时制的时间信息;
H 和 h输出的举例
mysql> select post_date,date_format(post_date,'%H') as '24H'
> ,date_format(post_date,'%h') as '12h'
> from maomao_posts limit 10;
+---------------------+------+------+
| post_date | 24H | 12h |
+---------------------+------+------+
| 2014-12-01 15:29:30 | 15 | 03 |
| 2014-12-01 15:32:13 | 15 | 03 |
| 2014-12-01 15:34:44 | 15 | 03 |
| 2014-12-01 15:35:36 | 15 | 03 |
| 2014-12-02 16:28:05 | 16 | 04 |
| 2014-12-04 15:11:16 | 15 | 03 |
| 2014-12-09 10:39:52 | 10 | 10 |
| 2014-12-09 10:45:27 | 10 | 10 |
| 2014-12-11 14:53:12 | 14 | 02 |
| 2014-12-18 08:50:15 | 08 | 08 |
+---------------------+------+------+
10 rows in set (0.00 sec)
date_format大小写h的用法