将时间和数字相加以获得总数

时间:2015-04-10 11:49:23

标签: php time

我需要将两种不同格式的两次加在一起:

  1. 发布时间' 12:30'
  2. 用户提交的号码(表示持续时间)Ex:1 =小时,0.5 = 30分钟
  3. 我需要将两者加在一起以获得总数,例如:12:30 + 0.5 = 14:00。

    我目前陷入困境并且错过了一些简单的事情,有人能指点我吗?

    代码:

    // Get Post Time
    $post_date = strtotime(get_the_date('G:i'));
    // Get User Submitted Number
    $post_duration = strtotime($course_hours);
    // Add Together
    $output = $post_date + $post_duration;
    // Output
    echo 'Start Time: '.get_the_date('G:i') .' - ';
    // Fail Here
    echo 'End Time: '. date('G:i', $output);
    

1 个答案:

答案 0 :(得分:3)

$add = 0.5 * 60 ; // convert posted hours to minutes 
$post_time = "12:30";
echo $post_date = date('G:i',strtotime("+ $add minutes" , strtotime($post_time)));