Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get timestamp from date('z') and year

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);
like image 465
Narek Avatar asked May 08 '12 13:05

Narek


People also ask

What is the Z in a timestamp?

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.

What is Z in timestamp Java?

The Z stands for the Zero timezone, as it is offset by 0 from the Coordinated Universal Time (UTC).

What is Z in UTC format?

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.


2 Answers

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

like image 150
Waboodoo Avatar answered Sep 18 '22 15:09

Waboodoo


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");

like image 29
core1024 Avatar answered Sep 19 '22 15:09

core1024