2

I have a unix timestamp stored in mysql of:

1438919940 

which when I convert it at http://www.onlineconversion.com/unix_time.htm it displays as

Fri, 07 Aug 2015 03:59:00 GMT // this is how I want to display it

In my code I am displaying it using:

$published = $row['update_date'];  //this is where 1438919940 comes from
$published = date ('jS F y @ g:ia',$published);
echo $published; 

but this displays as

7th August 15 @ 3:59am

The original strtotime I did was a PDT time and my server is set to Europe/London and in my script I have

date_default_timezone_set('Europe/London'); 

How are the online conversion site echoing that to the 'correct' (how I want it) version and I'm getting a date in the future!!

bertster
  • 383
  • 1
  • 3
  • 17

1 Answers1

3

Please try

date_default_timezone_set("GMT");
$published = $row['update_date'];
$published = date ('D, d M Y H:i:s T',$published);
echo $published;

Please refer to the following link for the date formats: http://php.net/manual/en/function.date.php

Deni George
  • 31
  • 1
  • 5
  • Welcome to SE! This looks like a good/correct answer. However, I think it might be improved a bit by adding a e.g. small explanation about the format specifiers and/or a link to a reference explaining it. – anderas Aug 06 '15 at 06:28
  • thanks andreas for the suggestions. – Deni George Aug 06 '15 at 06:39
  • GMT and UTC are the same. – Deni George Aug 06 '15 at 07:14
  • @DeniGeorge it now displays as Fri, 07 Aug 2015 03:59:00 GMT - again that's tomorrow!! – bertster Aug 06 '15 at 07:15
  • Sorry @DeniGeorge the point I'm making is that the date is displaying as a date in the future. It's come from a pubDate in an rss feed that is in a PDT time – bertster Aug 06 '15 at 07:16
  • 1
    The result is correct. See e.g. http://www.unixtimestamp.com/ : 1438919940 Is equivalent to: 08/07/2015 @ 3:59am (UTC) Whether that date is in the future or not is irrelevant. It is the time corresponding to the timestamp. – anderas Aug 06 '15 at 07:33
  • Yep, I just figured that too - thanks. I will look at how the timestamp is being generated. – bertster Aug 06 '15 at 07:37