confusion with adding 2 time values

前端 未结 3 1716
不思量自难忘°
不思量自难忘° 2021-01-23 06:19

Basically this whole time stuff is frustrating me, I am new to programming so I do apologise if I am asking a stupid question.

I have a MySQL time() stored in my databas

相关标签:
3条回答
  • 2021-01-23 06:33

    Strtotime is propagating a date inside there, something like "6PM today", instead of 6 hours like you intend. The easiest way to do this is to run

    time() + (6 * 3600);
    

    Where 6 is hours, and 3600 is the number of seconds in each hour.

    0 讨论(0)
  • 2021-01-23 06:37

    strtotime converts it to a unix time stamp. It DOES NOT represent six hours. It represents 6AM today. You should work with seconds:

    $duration = '06:00:00';
    $duration_array = explode(':', $duration);
    
    $length = ((int)$duration_array[0] * 3600) + ((int)$duration_array[1] * 60) + (int)$duration_array[2];
    $target = $length + time();
    
    0 讨论(0)
  • 2021-01-23 06:39

    I'm not too familiar with mySql, but perhaps you can try

    $target = strtotime($length) + time();
    
    0 讨论(0)
提交回复
热议问题