I’ve been using PHP for a while now – but when I need to use date() to format a time, I can never remember the hour syntax correctly. Is there any trick for remembering the rhyme and reason for using g/G/h/H ?
From the PHP manual for date() :
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
and in image format:
php-time.png http://img593.imageshack.us/img593/5338/phptime.png
I have no idea what the actual reason is, but …
horHis obviously hours. The capital letter is bigger, so it uses a bigger number of hours (24 vs. 12).gorGishorHwithout the leading0.gimmediately precedeshin the alphabet.You’re going to want the leading
0more often than not (because it aligns better), so that format gets thehfor hours.If that works for you, great. If not, consider writing the table on a Post-it® Note and sticking it to your monitor.