Get timestamp from date ('z') and year

I know the year and day of the year (0-365). Is there any way to get back from it to the timestamp?

Sort of:

$day=date('z'); $year=2012; $timestamp=strtotime($day.'-nd day of '.$year); 
+6
source share
3 answers

Try the following:

$timestamp = mktime(0,0,0,1,$day,$year);

It will create a timestamp where the time is set to 0:00:00. (I'm not sure that he will behave correctly in relation to summer savings, though ...)

Read the PHP manual for more details: PHP: mktime - Manual

+4
source

Maybe strtotime will be useful here: php -r 'echo @date("Ymd H:s", strtotime("january 2012 +200 day")).PHP_EOL;' In your example, $timestamp = strtotime("january $year +$day day");

+2
source

Try using createFromFormat :

 $date = DateTime::createFromFormat('z Y', $day . ' ' . $year); echo $date->getTimestamp(); 
+1
source

Source: https://habr.com/ru/post/915201/


All Articles