4

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.

2
  • 2
    Not really a duplicate as the other question mentions a specific format from a function, not an RFC 3339 output from Javascript Date. Commented Jun 17, 2014 at 8:25
  • Instead of relying to javascript toString, you should use toISOStringto get a standard date format (which is well recognized by php strtotime). Commented Jun 17, 2014 at 8:35

1 Answer 1

7

(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));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.