add hours:min:sec to date in PHP

前端 未结 3 661
梦谈多话
梦谈多话 2021-01-18 08:05

I am trying to add hh:mm:ss with the date. How can i do it?

I tried with the following but it works when the hour is string, but when adding time is similar to MySQL

3条回答
  •  没有蜡笔的小新
    2021-01-18 08:31

     print date('Y-m-d H:i:s',strtotime($timeA." +03 hour +05 minutes +01 seconds"));  
    

    Should work also.

    So:

    $timeA= '2015-10-09 13:40:14'; 
    
    $timeB = vsprintf(" +%d hours +%d minutes +%d seconds", explode(':', '03:05:01')); 
    
    print date('Y-m-d H:i:s',strtotime($timeA.$timeB));
    

    Can be the solution.

提交回复
热议问题