php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47513 when using date, H shows 01 instead of 00
Submitted: 2009-02-26 22:59 UTC Modified: 2009-02-28 20:30 UTC
From: usrhlp at yahoo dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.8 OS: Debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: usrhlp at yahoo dot com
New email:
PHP Version: OS:

 

 [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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-26 23:07 UTC] usrhlp at yahoo dot com
I just tried it on another server I have with php 5.2.6 and i get this result

18:00.01
18:00.10
18:01.40
18:16.40
20:46.40
21:46.40
07:46.40
12:46.40

That has totally thrown me off.
 [2009-02-27 21:59 UTC] shaunspiller at gmail dot com
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');
}
 [2009-02-28 20:29 UTC] usrhlp at yahoo dot com
Thank you, GMDATE has fixed the issue!!

Please close this bug as erroneous.
 [2009-02-28 20:30 UTC] usrhlp at yahoo dot com
use GMdate instead of date.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 10 19:01:34 2024 UTC