SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Apr 2001
    Location
    Arizona
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a question about the date() function in PHP. When I am trying to post the time on my website it works, but it posts the time on the East Coast. How do I get it to recognize that I am in Arizona and I want to use MST? Here is my code...

    echo date("g:i:s a T")

    Thank you for your help
    Viper420

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Most likely because your server is set to EST, in order to change that you need mktime and subtract 2 hours from the hour argument, at least I think its 2 hours.


    echo date("g:i:s a T", mktime(date("g") - 2, date("i"), date("s"), date("m"), date("d"), date("Y")));
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Member
    Join Date
    Apr 2001
    Location
    Arizona
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used the code that you supplied and everything worked except now it shows a.m. instead of p.m.?

    This is the exact code -->

    echo date("g:i:s a", mktime(date("g") - 3,
    date("i"), date("s"), date("m"), date("d"), date("Y")));

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    viper, my bad a lowercase g returns 0 - 12 we need 24 hour time so in your mktime make the lowercase g a uppercase G


    echo date("g:i:s a", mktime(date("G") - 3,
    date("i"), date("s"), date("m"), date("d"), date("Y")));
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Member
    Join Date
    Apr 2001
    Location
    Arizona
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Freddy...That worked perfect.

    Viper420

  6. #6
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using putenv().

    Like that:
    putenv('TZ=Arizona');

    I don't know what you must write after TZ to get it to recognize Arizona's timezone, though, but you can find this out.

    putenv('TZ=') lets you set the correct timezone at the beginning of your script so you don't have to play with mktime every now and then.
    [blogger: zengun] [blogware contributor: wordpress]


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
  •