PHP Adding 15 minutes to Time value

后端 未结 7 2295
一整个雨季
一整个雨季 2020-11-27 07:35

I have a form that receives a time value:

$selectedTime = $_REQUEST[\'time\'];

The time is in this format - 9:15:00 - which is 9:15am. I t

7条回答
  •  不知归路
    2020-11-27 07:42

    Your code doesn't work (parse) because you have an extra ) at the end that causes a Parse Error. Count, you have 2 ( and 3 ). It would work fine if you fix that, but strtotime() returns a timestamp, so to get a human readable time use date().

    $selectedTime = "9:15:00";
    $endTime = strtotime("+15 minutes", strtotime($selectedTime));
    echo date('h:i:s', $endTime);
    

    Get an editor that will syntax highlight and show unmatched parentheses, braces, etc.

    To just do straight time without any TZ or DST and add 15 minutes (read zerkms comment):

     $endTime = strtotime($selectedTime) + 900;  //900 = 15 min X 60 sec
    

    Still, the ) is the main issue here.

提交回复
热议问题