On Dec 28, 2007 5:48 PM, tedd <[EMAIL PROTECTED]> wrote:
[snip!]
> Here is the code and demo:
>
> http://webbytedd.com/c/unix-time1/index.php
>
> It works for me on my server.
[snip!]
Well, if you don't want to change the timezone at runtime like I
suggested this morning, you could do something with the date("O");
switch to see the difference.
THIS IS UNTESTED, AND BEING TYPED BY AN EXHAUSTED GEEK WHO'S READY
FOR NEW YEARS' VACATION!!!!
<?php // ----========== functions =============----------
function dateToUnix($datetime) // in the form of 12-25-2007 00:00:00
{
$parts = explode(' ', $datetime); // separate 12-25-2007 from 00:00:00
if (count($parts) != 2)
{
return;
}
$date_parts = explode('-', $parts[0]); // separate 12-25-2007
if (count($date_parts) != 3)
{
return;
}
$time_parts = explode(':', $parts[1]); // separate 00:00:00
if (count($time_parts) != 3 )
{
return;
}
$my_timezone = +0500; // To denote EST (GMT -0500) - Change to
whatever you want.
if(date("O") > $my_timezone)
{
substr($my_timezone,0,1) == "-" && substr(date("O"),0,1) == "-"
? $time_parts[0] = (($time_parts[0] + date("O")) - $my_timezone)
: null;
substr($my_timezone,0,1) == "-" && substr(date("O"),0,1) == "+"
? $time_parts[0] = (($time_parts[0] - date("O")) - $my_timezone)
: null;
substr($my_timezone,0,1) == "+" && substr(date("O"),0,1) == "+"
? $time_parts[0] = (($time_parts[0] - date("O")) + $my_timezone)
: null;
substr($my_timezone,0,1) == "+" && substr(date("O"),0,1) == "-"
? $time_parts[0] = (($time_parts[0] + date("O")) + $my_timezone)
: null;
}
return mktime($time_parts[0], $time_parts[1], $time_parts[2],
$date_parts[0], $date_parts[1], $date_parts[2],-1);
}
echo date("m/d/Y H:i:s",dateToUnix("12-28-2007 18:30:46"))."\n";
?>
--
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]
If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php