timestamp does not indicate the correct date

4

I'm working on a CMS for display of articles, my problem is with the function strtotime() does not indicate the correct date, always indicates March 1, 1970. A row (phpMyAdmin) of the article_timestamp is given with the format: ex. 1394220287 . What am I doing wrong?

<span id="date">Publicado  
<?php
    setlocale(LC_ALL, NULL);
    date_default_timezone_set('Europe/Lisbon');
    $timeStamp = $article['article_timestamp'];
    $uppercaseMonth = ucfirst(gmstrftime('%B'));
    echo strftime( '%A, %d de ' .$uppercaseMonth. ' de %Y', strtotime($timeStamp));
?></span>
    
asked by anonymous 09.03.2014 / 11:31

3 answers

4

From the example you asked the question, I see that $timeStamp is already a timestamp , so you do not need strtotime () .

Use only:

echo strftime( '%A, %d de ' .$uppercaseMonth. ' de %Y', $timeStamp);
//                                                     ^^ - tirei o strtotime()

Example in PHP Fiddle

    
09.03.2014 / 11:56
0

If the date format passed to strtotime() is not valid, the function returns false . Use DateTime::createFromFormat() to convert dates to timestamp:

DateTime::createFromFormat('Y-m-d H:i:s', '2014-01-01 12:00:00');
    
09.03.2014 / 11:49
0

You can bring the correct MySQL date / time using the FROM_UNIXTIME ()

SELECT
  FROM_UNIXTIME(article_timestamp, '%W, %d de %M de %Y %h:%i:%s') 
FROM 
  sua_tabela
    
14.03.2014 / 00:32