php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54253 Date H (and h) returns +7 hours
Submitted: 2011-03-14 23:58 UTC Modified: 2011-03-15 00:31 UTC
From: sunco007 at hotmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.5 OS: Windows 7 x32
Private report: No CVE-ID: None
 [2011-03-14 23:58 UTC] sunco007 at hotmail dot com
Description:
------------
Want to get the date without any calculations and i got it wrong

Is 15:54:09 and Php..

date("H:i:s") returns me 22:54:09
date("h:i:s") returns me 10:54:09

Maybe you need to check exactly on March 14 2011 to see the same result as me

Test script:
---------------
<?
echo date("H:i:s");
// or
echo date("h:i:s");
?>

Expected result:
----------------
Current time

Actual result:
--------------
The time +7 hours

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-15 00:02 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2011-03-15 00:02 UTC] rasmus@php.net
Set your timezone. You are getting UTC back.

date_default_timezone_set('America/Denver');
 [2011-03-15 00:03 UTC] rasmus@php.net
Or I guess you are Pacific actually. Then use:

date_default_timezone_set('America/Los_Angeles');
 [2011-03-15 00:28 UTC] sunco007 at hotmail dot com
Ok. Your answer is the correct but..

Do i need to add that line to ALL my php files ? (lets say i have 100)

Ok.. i can change one line on php.ini but.. What about if I use a hosting provider and they don't want to change it ?

I think is much better if Php reads the timezone directly from the PC, just as Mysql does

What do you think about that ?
 [2011-03-15 00:31 UTC] rasmus@php.net
It does try to detect it. Many servers run in UTC by default, so yes, you should 
set your timezone in your php.ini or if you don't have access to that in some 
common include file.
 [2011-03-15 00:39 UTC] sunco007 at hotmail dot com
Ok, in my case must add the line on common header file (the 100 files was just an example)

Thanks for your time
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 01 12:01:31 2024 UTC