Convert day of the year to datetime in php

后端 未结 2 836
抹茶落季
抹茶落季 2021-01-29 10:44

I have value

$days = 166.0444; 

which is day of the year. How can I simply convert this value to its datetime, which should be



        
2条回答
  •  生来不讨喜
    2021-01-29 11:09

    You can do it in this or similar way:

    function convertDaysToDateTime($days, $year){
        $datetime = new DateTime();
        return $datetime->setTimestamp(mktime(0,0,0,0,0,$year) + $days * 24 * 3600);
    }
    
    $days = 166.0444;       
    $datetime = convertDaysToDateTime($days, date('Y'));
    
    echo $datetime->format('U = Y-m-d H:i:s');
    

提交回复
热议问题