I know the year and the day of year (0-365). Is there any way to get back from it to timestamp?
Something like:
$day=date('z');
$year=2012;
$timestamp=strtotime($day.'-nd day of '.$year);
The Z stands for 'Zulu' - your times are in UTC. From Wikipedia: The UTC time zone is sometimes denoted by the letter Z—a reference to the equivalent nautical time zone (GMT), which has been denoted by a Z since about 1950.
The Z stands for the Zero timezone, as it is offset by 0 from the Coordinated Universal Time (UTC).
Z is the zone designator for the zero UTC offset. "09:30 UTC" is therefore represented as "09:30Z" or "T0930Z". "14:45:15 UTC" would be "14:45:15Z" or "T144515Z". The Z suffix in the ISO 8601 time representation is sometimes referred to as "Zulu time" because the same letter is used to designate the Zulu time zone.
Try the following:
$timestamp = mktime(0,0,0,1,$day,$year);
It will produce a timestamp where the time is set to 0:00:00. (I am not sure if it will behave correctly with respect to daylight savings though...)
Check the PHP manual for further details: PHP: mktime - Manual
Maybe strtotime gets handy here:
php -r 'echo @date("Y-m-d H:s", strtotime("january 2012 +200 day")).PHP_EOL;'
In your example $timestamp = strtotime("january $year +$day day");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With