H.HISTORY
H.HISTORY

Reputation: 518

PHP: strtotime revered return strange date?

I am using php strtotime and mysql datetime for a simple countdown to a certain date.

I also use jQuery to countdown.

my jquery strtotime time is like this: 1443661380000

if I run my jquery countdown without any php, it works just fine and counts down properly.

However, when I use the mysql datetime and php strtotime like so : $long = strtotime("$fes_events_date"); my jquery countdown stops working.

so I tried to reverse the jquery strtotime which is 1443661380000 so I can see what it looks like in case I am missing something in my php strtotime.

so I did this:

    $hin = date("Y-m-d H:i:s", 1443661380000);
echo $hin;

and the output of that is something strange which is the following:

47717-10-22 18:00:00

so the question that I have is that How can I convert my datetime mysql using php strtotime so I get the same kind of output in order to make my jquery countdown to work?

any help would be appreciated.

Upvotes: 1

Views: 388

Answers (3)

Alana Storm
Alana Storm

Reputation: 166066

The unix timestamp, the second argument to the date function, is the number of seconds since January 1, 1970.

For reasons that are lost to the mists of history, the javascript timestamp is the number of milliseconds since the unix epoch. The PHP strToTime function doesn't recognize that and can't do its magic. You'll need to manually convert your milliseconds to seconds.

$hin = date("Y-m-d H:i:s", (1443661380000/1000));
echo $hin;

Upvotes: 2

Matt Clark
Matt Clark

Reputation: 28579

Know that measuring UNIX / Epoch Time is usually done in one of two ways, either in seconds, or in milliseconds since January, 1 1970.

It would appear to me that you have a time in milliseconds, whereas the function that you are trying to use is converting it as if it were in seconds, therefore you are off by a factor of 1000.

Try diving your time by 1000 and then passing it into the converter.

1000ms/1000 = 1s
1443661380000ms / 1000 = 144366138s

144366138s -> Date -> GMT: Thu, 01 Oct 2015 01:03:00

Upvotes: 1

user4628565
user4628565

Reputation:

try to change,

$hin = date("Y-m-d H:i:s", 1443661380000);

to

$mil=1443661380000;
$seconds = $mil / 1000;
$hin = date("Y-m-d H:i:s", $seconds);

Upvotes: 2

Related Questions