Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert javascript datetime into php datetime [duplicate]

I want to convert javascript date Mon Jun 23 2014 16:17:05 GMT+0530 (India Standard Time) into PHP datetime. I tried

echo date('Y-m-d h:i:s', strtotime($expire_time));

where $expire_time is Mon Jun 23 2014 16:17:05 GMT+0530 (India Standard Time) but it is giving 1970-01-01 12:00:00.

Please help.

like image 528
user3588408 Avatar asked Mar 19 '23 07:03

user3588408


1 Answers

(India Standard Time) causes the problem with parsing, so you need to remove it from the string before calling date(). You can use something like:

$expire_time = 'Mon Jun 23 2014 16:17:05 GMT+0530 (India Standard Time)';
$expire_time = substr($expire_time, 0, strpos($expire_time, '('));

echo date('Y-m-d h:i:s', strtotime($expire_time));
like image 52
Gergo Erdosi Avatar answered Mar 21 '23 22:03

Gergo Erdosi