0

How can i know timestamp of today at 18.00 UTC with php ? (obviously i don't know what day is today).

So i tried this:

$timestamp_now= time(); 
$today= gmdate("d-m-Y", $timestamp_now);    //output for today 20-02-2020

$output= strtotime($today." 18:00"); //i tried to get timestamp for (utc data)

For 20-02-2020 18.00 UTC the timestamp should be:

 Epoch timestamp: 1582221600

But with my code the output is about 20-02-2020 23.00 (i don't know what time zone):

       timestamp: 1582239600

What is the error ?


EDIT i solved my question:

$timestamp_now= time(); 

$oggi_giorno= gmdate("d", $timestamp_now); //get utc day for today
$oggi_mese= gmdate("m", $timestamp_now); //get utc month for today
$oggi_anno= gmdate("Y", $timestamp_now); //get utc year for today

$output= gmmktime(18, 0, 0, $oggi_mese, $oggi_giorno, $oggi_anno);

//THE OUTPUT IS: 1582221600 

The output is correct because is about 20-02-2020 18.00 UTC so to get timestamp for UTC Date must to use gmmktime !

Thanks.

Borja
  • 3,359
  • 7
  • 33
  • 66
  • 1
    Duplicate of get UTC time in PHP https://stackoverflow.com/questions/8655515/get-utc-time-in-php –  Feb 20 '20 at 12:11
  • not clear why you just don't call gmdate like `$utc = strtotime(gmdate("d-m-Y 18:00:00"));` if you need the UTC timestamp for 18:00? – mitkosoft Feb 20 '20 at 12:12
  • @mitkosoft tried your suggestion....the wrong output is the same like my code. I want to get timestamp for 18.00 UTC – Borja Feb 20 '20 at 12:15
  • 1
    @Borja, `echo strtotime(gmdate("d-m-Y 18:00:00"));` gives always `1582221600`. not sure how your code looks like after the change. – mitkosoft Feb 20 '20 at 12:17
  • @mitkosoft i solved...see the edit – Borja Feb 20 '20 at 12:29
  • overcomplicated as you can achieve the same with a single line. – mitkosoft Feb 20 '20 at 12:31
  • @mitkosoft so help me because your suggestion doesn't work :D trust me – Borja Feb 20 '20 at 12:37

0 Answers0