0

可変時間から7時間カウントダウンするにはどうすればよいですか(タイムスタンプが挿入されたテーブルから時間を取得します)、可変時間から7時間後にテーブルを更新します。

私はそのようなものが必要です

$time = 2013-05-18 02:00:00 // comes from database
$target = $time + 7hours // time from database +7hours will be 2013-05-18 09:00:00
$until = $target - $time

以下のコードのようなものが必要です

if ($until > 0 ) {
    echo "you need to wait for $until hours"
} else {
    echo "time is ok"; // i will update a table
}
4

2 に答える 2

0

So, considering that $database_time is the stored time, in your db, and $time_now is your computers time, this message below, just echoed out:

You Must wait 4 hours right, now

It could be done much better, but still calculates the hours from now, to db and tells you how much more, you must wait :)

<?php
   $date = date_create();
   $database_time = '2013-05-18 22:00:00';
   $time_now =  date_format($date, 'Y-m-d H:i:s');

   $check =  $database_time[11];
   $check .=  $database_time[12];
   $check2 = $time_now[11];
   $check2 .= $time_now[12];

   $time_left =  $check - $check2;

So, here is how you can manage your ourputs

 if($time_left > 0) {
   echo "You Must wait $time_left  hours right, now"; 
 }else{
   echo "Time is OK";
 }
于 2013-05-18T18:36:15.270 に答える