Good afternoon, there is a form from which I get the date in the format "yyyy-mm-ddTH: M". It is necessary to receive in a timestamp format. Made the function, but for some reason does not return the value imputed. Instead of the entered date, I get 1999. Please tell me, at what stage in the function did I make a mistake?

<?php $datic = '2016-06-10T10:10'; echo create_timestamp($datic); function create_timestamp($datic){ $date = str_replace("T", " ", $datic); //убираю лишнюю Т $strf = strftime('%Y-%m-%d %H:%M'); $dt = strptime ($date, $strf); return mktime($dt['tm_hour'], $dt['tm_min'], $dt['tm_sec'], $dt['tm_mon'], $dt['tm_mday'], $dt['tm_year']); } ?> 

    2 answers 2

     $ datic = '2016-06-10T10: 10';
     echo strtotime ($ datic);  // 1465546200
     echo date ('Ymd \ TH: i', strtotime ($ datic));  // 2016-06-10T10: 10
    

      Why don't you use DateTime, are there any restrictions?

       $datic = '2016-06-10T10:10'; $dateTime = new DateTime($datic); echo $dateTime->getTimestamp(); 
      • This method works, but I do not get an accurate result. For example $ datic = '2016-06-10T10: 10' in the timestamp - 1465567800, if you translate this back, you get a misunderstanding with time. In the original version of the time 10:10, and in the resulting 14:10 - user137
      • one
        And you consider the time zone? - Roman Grinyov