在php的date()语法中,g / G / h / H有什么助记设备或押韵/原因?

时间:2012-09-25 03:31:06

标签: php date time

我一直在使用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

1 个答案:

答案 0 :(得分:1)

我不知道实际的原因是什么,但是......

hH显然是小时。大写字母更大,因此它使用更多的小时数(24对12)。

gGhH,不含前导0g紧跟在字母表中的h之前。

您经常需要领先的0(因为它更好地对齐),因此格式会在h达到数小时。

如果这对你有用,那很好。如果没有,请考虑将表格写在Post-it® Note上并将其粘贴到您的显示器上。