|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-02-26 22:59 UTC] usrhlp at yahoo dot com
Description: ------------ I am probably doing something wrong but I cannot for the life of me figure out what it is. I am trying to convert a small number to 24 hour time format. For example I'm parsing the number 5 through the date function and I am receiving the answer 01:00.05 I checked the PHP documentation and it shows as this for date() H 24-hour format of an hour with leading zeros 00 through 23 According to the documentation 00 is a possible output of the H formatting within date and should be what is coming out. Reproduce code: --------------- echo(date("H:i.s" ,1)); echo(date("H:i.s" ,10)); echo(date("H:i.s" ,100)); echo(date("H:i.s" ,1000)); echo(date("H:i.s" ,10000)); echo(date("H:i.s" ,100000)); echo(date("H:i.s" ,1000000)); echo(date("H:i.s" ,10000000)); Expected result: ---------------- time: 00:00.01 time: 00:00.10 time: 00:01.40 time: 00:16.40 time: 03:46.40 time: 04:46.40 time: 14:46.40 time: 18:46.40 Actual result: -------------- time: 01:00.01 time: 01:00.10 time: 01:01.40 time: 01:16.40 time: 03:46.40 time: 04:46.40 time: 14:46.40 time: 18:46.40 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 22:00:01 2025 UTC |
It's the time zone on your machine. The number "5" refers to the time January 1 1970 @ 00:00:05 UTC, which date() will format as something different if you're in CET, etc. Use the format codes 'O' or 'P' to show the timezone offset. If you want it always fixed at UTC, use gmdate() instead of date(). Or use date_default_timezone_set first. E.g., if (version_compare(PHP_VERSION, '5.1.0', '>=')) { date_default_timezone_set('UTC'); }