SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    My server and where I reside are in different timezones.

    How do I set it to be the same as my timezone?
    Like adding +10 or something to the time?

    How do I go about it?

    thanks
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  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)
    //Set offset to be the numbe rof hours ahead you want
    $offset = "10";
    $adj_time = date("g:i:s a", mktime(date("H")+$offset,date("i"),date("s")));
    //$adj_time will contain the new time
    print $adj_time;


    [Edited by freddydoesphp on 10-22-2000 at 12:05 AM]
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks for helping.

    I was also wondering..how do I set the offset for dates?
    Since my offset between the server and my timezone is +15, how do i make the dates reflect too?

    this is my script version. thanks

    <?php
    $last_modified = filemtime("$SCRIPT_FILENAME"); print(date("d/m/y", $last_modified));
    ?>
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  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)
    This will show the date reflected by the offset, is that what you are after?
    $offset = "15";
    $adj_time = date("g:i:s m/d/y", mktime(date("H")+$offset,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 Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow, that's quite cool. Mind if I make use of it?

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually since one interested me more than normal so I came up with a little function to return a new date and time based on an offset that you set as a parameter. If there are better ways of doing this please someone chime ine, I am alwasy looking for improvement. But here goes:
    function adj_timezone($meth, $hour) {
    if ($meth == "+") {
    $adj_time = date("g:i:s a | m/d/y", mktime(date("H")+ $hour,date("i"),date("s"), date("m"), date("d"), date("y")));
    $time = explode("|", $adj_time);
    }
    elseif($meth == "-") {
    $adj_time = date("g:i:s a | m/d/y", mktime(date("H")- $hour,date("i"),date("s"), date("m"), date("d"), date("y")));
    $time = explode("|", $adj_time);
    }
    else {
    $time = "";
    }
    return $time;
    }


    //Sample Usage: to go back timezones
    $time = adj_timezone("-", 10);
    //Or to move forward
    $time = adj_timezone("+", 10);

    //Function returns an array the first element holds the new time the second the new date
    $newtime = $time[0];
    $newday = $time[1];
    print $newtime."<br>";
    print $newday."<br>";
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I'm getting the time and date fom when a file was last modified. So how do i set the offset for it? Using your functions?

    thanks for your help..=))
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?
    function adj_timezone($meth, $hour, $moddate) {
    $hour = ($hour * 3600);
    if ($meth == "+") {
    $newtime = $moddate + $hour;
    }
    elseif($meth == "-") {
    $newtime = $moddate - $hour;
    }
    else {
    $time = "";
    }
    $adj_time = DATE("m-d-y | g:i:s a", $newtime);
    $time = explode("|", $adj_time);
    return $time;
    }

    $moddate = filemtime("./iplister.php");

    //To move forward three params(-/+, number of hours, filemtime
    $time = adj_timezone("+", 10, $moddate);

    //Function returns an array the first element holds the new time the second the new date
    $newtime = $time[0];
    $newday = $time[1];
    print $newtime."<br>";
    print $newday."<br>";

    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    Non-Member
    Join Date
    Apr 2000
    Location
    Waco, Texas.
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could also do it this way:

    Code:
    <?
    $offset = '10'; #hours
    $offset_time = time() + ($offset * 3600); #3600 seconds in one hour
    $readable_offset_time = date("g:i A",$offset_time);
    
    echo $readable_offset_time;
    ?>
    $offset can be changed to - or + numbers.

  10. #10
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah but what if you wanted to use it more than once on your page, you would have to write that code every time, why not make a function out of it, and then you can call on the function with one line of code whenever you need it?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  11. #11
    Non-Member
    Join Date
    Apr 2000
    Location
    Waco, Texas.
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    True. Here is a function for the code
    Code:
    <?
    function time_offset($offset)
    {
    	$offset_time = time() + ($offset * 3600); #3600 seconds in one hour
    	$readable_offset_time[0] = date("g:i A",$offset_time);
    	$readable_offset_time[1] = date("F d, Y g:i A",$offset_time);
    	return $readable_offset_time;
    } 
    
    $time = time_offset('-24');
    echo $time[1]; #for date and time
    echo $time[0]; #for just time
    ?>
    *edit*
    included function to display date also if wanted.

    [Edited by robp on 10-23-2000 at 12:49 PM]

  12. #12
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, well what if they want to subtract hours, your function doesn't allow for that, furthermore the one I posted above allows for this and returns a nice array with the date and the time. Though they pretty much do the same thing
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  13. #13
    Non-Member
    Join Date
    Apr 2000
    Location
    Waco, Texas.
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not to get in an argument about who's function is better , but the one I wrote can actually subtract time if the offset is negative.

  14. #14
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used freddy's very first tiny little function and used "-4" and it worked like a charm...

  15. #15
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't want to argue about something so silly either, but what the guy was looking for who started the post was a way to take the value of filemtime() and add 10 hours to it, so that is what I gave hime, yours is good, but it isn't what he was after.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  16. #16
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Guys,

    Thanks for your help.
    But Hey, there ain't a need to quarrel. Both functions are good in their own ways and I'm keeping both for reference.
    robp's would be good for just displaying the time yah? =)

    Anyhow,
    I'm using freddydoesphp's as it allows more configurations and allow me to set the file last modified too.

    Thnaks for your help.
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein


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
  •