Code: Select all
<?php
$paydate = "18:30:30 Jan 1, 2000 PST";
$dt = date('H:i:s M j, Y T', $paydate);
print date('M-j-Y H:i:s T', $dt);
?>'Dec-31-1969 19:00:19 Eastern Standard Time'
anyone know why or how I can fix this ?
Moderator: General Moderators
Code: Select all
<?php
$paydate = "18:30:30 Jan 1, 2000 PST";
$dt = date('H:i:s M j, Y T', $paydate);
print date('M-j-Y H:i:s T', $dt);
?>Code: Select all
// stolen from php.net comments...
/*
$current should be the timezone on the
current machine, $target is the timezone
you want to calculate. Both should be in
hours. For example, GMT -05:00 should
be -5. GMT +12:00 should be 12. You can
use the returned timestamp with the date
function.
ex: echo date('r', zonechange(-5, 10));
would echo the date for a +10:00
timezone on a machine in -05:00.
*/
function zonechange ($current, $target) {
$current = -1 * $current;
$zonedate = mktime(date('G'), date('i'), date('s'), date('n'),
date('j'), date('Y'), 1) + (($current + $target) * 3600);
return $zonedate;
}To generate a timestamp from a string representation of the date, you may be able to use strtotime(). Additionally, some databases have functions to convert their date formats into timestamps (such as MySQL's UNIX_TIMESTAMP function).
Code: Select all
<pre>
<?php
$paydate = "18:30:30 Jan 1, 2000 PST";
echo $paydate."\n";
$foo = strtotime($paydate);
echo $foo."\n";
$bar = date('H:i:s M j, Y T', $foo);
echo $bar."\n";
?>
// 18:30:30 Jan 1, 2000 PST
// 946780230
// 03:30:30 Jan 2, 2000 W. Europe Standard TimeCode: Select all
<pre>
<?php
putenv ("TZ=PST8PST");
$one = "18:30:30 Jan 1, 2000 PST";
$one = strtotime($one);
$one = date('H:i:s M j, Y T', $one);
echo 'One: '.$one."\n";
?>