我一直在使用PHP一段时间 - 但是当我需要使用date()
格式化时间时,我永远无法正确记住小时语法。有没有记住使用g / G / h / H的押韵和理由的技巧?
来自date()
的PHP手册:
g | 12-hour format of an hour without leading zeros | 1 through 12
G | 24-hour format of an hour without leading zeros | 0 through 23
h | 12-hour format of an hour with leading zeros | 01 through 12
H | 24-hour format of an hour with leading zeros | 00 through 23
以图像格式:
php-time.png http://img593.imageshack.us/img593/5338/phptime.png
答案 0 :(得分:1)
我不知道实际的原因是什么,但是......
h
或H
显然是小时。大写字母更大,因此它使用更多的小时数(24对12)。
g
或G
为h
或H
,不含前导0
。 g
紧跟在字母表中的h
之前。
您经常需要领先的0
(因为它更好地对齐),因此格式会在h
达到数小时。
如果这对你有用,那很好。如果没有,请考虑将表格写在Post-it® Note上并将其粘贴到您的显示器上。