Results 1 to 8 of 8

Thread: Php time 2 hours different

  1. #1
    Join Date
    Mar 2011
    Location
    N 11░ 19' 0.0012 E 142░ 15' 0
    Posts
    1,509
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default Php time 2 hours different

    PHP Code:
    $date time();
    echo 
    date("j F Y - g:i a"$date); 
    outputs

    22 April 2012 - 2:27 pm

    when it should output

    22 April 2012 - 12:27 am

    I'm running this on WAMP on my home computer. Any help?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Is this an example of the problem or a specific problem for the date() function?

    It sounds to me like either your PHP configuration either is set to the wrong timezone, or your default active timezone in PHP is wrong.

    Those sound similar, but they're not. PHP knows what time it is. But that might be wrong (off by 2 hours). And/or when you use date() it uses whatever timezone setting is active, usually determined by a default timezone, relative of course to PHP's base time setting. In other words, does PHP not know the right time, or does PHP just think you want to output time for somewhere else?
    Of course it could also be a server-level problem. Maybe check your logs to see if the logs also have weird times on them.

    You can try to figure out the details and fix them, or you can just set another timezone during runtime (or via .htaccess, or php.ini).
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2011
    Location
    N 11░ 19' 0.0012 E 142░ 15' 0
    Posts
    1,509
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    This is an actuall problem I'm having. I'll have a go at what you suggested and get back to you.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    My first sentence wasn't clear-- I was asking whether you were using date() to demonstrate the problem (with the server in general) or if this problem was specific (and limited to) the date() function.

    But that's fine-- post back when you know more and I'll see if I can think of anything. Unfortunately with something like this, it ends up often just being a lot of trial and error until you eventually find the source of the problem.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Mar 2011
    Location
    N 11░ 19' 0.0012 E 142░ 15' 0
    Posts
    1,509
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    I believe it is a problem with time() in general not just date().

  6. #6
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,689
    Thanks
    82
    Thanked 89 Times in 87 Posts

    Default

    What happens when you set the timezone with the following at the top of your script?

    Code:
    date_default_timezone_set('America/Chicago');
    You could also add the same thing to your php.ini file. It would look like the following though:

    Code:
    date.timezone = "America/Chicago"
    If you are making this change to your php.ini file the changes may not take place right away depending on your hosting service. I use godaddy and in order for the changes to take place immediately I go to the godaddy website, access my hosting service and select end system processes. You might not have a godaddy hosting account, but a number of people do. If you need more details with how to do what I just described let me know and I can give a more detailed answer.

    I might be totally barking up the wrong tree with this post though.
    To choose the lesser of two evils is still to choose evil. My personal site

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,925
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    Why Chicago? keyboard1333's location puts him in the Mariana Trench. I suppose that's some sort of reference to something else though. Where are you really? That's where you should be setting your timezone for. See:

    http://www.php.net/manual/en/timezones.php

    for the list of supported zones.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Mar 2011
    Location
    N 11░ 19' 0.0012 E 142░ 15' 0
    Posts
    1,509
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    Quote Originally Posted by jscheuer1 View Post
    Why Chicago? keyboard1333's location puts him in the Mariana Trench. I suppose that's some sort of reference to something else though.
    It's called a joke
    and I'm guessing because he was using his hometown as an example??? (correct me if I'm wrong)

    Thanks for all the suggestions guys. I'll have a go to setting the timezone later. Thanks again.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •