-1

可能重复:
strtotime date 奇怪的结果

我试图比较考勤系统的两次,我试图获得美国阿肯色州的准确时间,但我无法获得正确的时间。如果我做错了什么,请引导我朝着正确的方向前进,这是我的代码的一部分:

$curTime =DATE("H:i A", strtotime('GMT-6'));

foreach($res as $r)
{
    $crs_id =$r['course_id']; 
    $query1 = "select * from tbl_course_time where course_id='$crs_id'";

     $res1 = $obj->querySelect($query1);


     $start_time  = DATE("H:i", STRTOTIME($res1[0]['start_time']));
     $end_time = DATE("H:i", STRTOTIME($res1[0]['end_time']));

    if ($curTime > $start_time && $curTime < $end_time) 
    {

      $qry="insert into tbl_attendance set         stud_id='$id',attd_date='$curDateForDB',attd_time='$curTimeForDB',course_id='$attd_courseId'";

    $res=$obj->queryInsert($qry);

    $result1 = "taken";
   }
}

它给了我不正确的时间是格林威治标准时间我弄错了还是其他任何帮助将不胜感激,谢谢

4

2 回答 2

1

Don't use strtotime('GMT-6') because GMT-6 is not a time; it's a time zone.

// gets the UTC time using gmdate() instead of date()
$utc_str = gmdate("M d Y H:i:s", time());

// get the UTC timestamp, should you need it
$utc = strtotime($utc_str);

If you're in PHP 5, the DateTime class is a very clean way to get times and also deal with time zone conversions.

Also, I encourage you to set your database up using UTC time, and convert the output to the user's time zone.

于 2012-12-13T14:42:36.317 回答
0

You're doing the gmt-6 business wrong. The following is on a server that's in GMT-6 already:

echo date('r');                     // Thu, 13 Dec 2012 02:40:00 -0600
echo date('r', strtotime('gmt-6')); // Thu, 13 Dec 2012 08:40:17 -0600

Note the 6 hour difference (and 17 seconds while I was typing up the strtotime bits). Doing the gmt-6 bit in strtotime forces PHP to apply a 6 hour difference to a string that's already in some timezone already.

于 2012-12-13T14:44:39.770 回答