0

I have a string:

Mon Jul 07 2014 13:47:03 GMT+0800 (Malay Peninsula Standard Time)

I want to convert to unix timestamp in PHP.

However using strtotime() does not work for me. Is there any other work around so I can get the unix timestamp from this string?

2
  • 2
    is that the exact string? Mon Jul .... Standard Time)? strtotime() is good, but you can't just throw anything you want it. you should strip off the "(Malay Penninsula Standard Time)" at least. Commented Jul 7, 2014 at 21:55
  • Yes that is the exact string, i am trying to convert the lastdatemodified from a javascript function when it throws over the value to my php end Commented Jul 7, 2014 at 21:56

1 Answer 1

1

First, strip (Malay Peninsula Standard Time) because you have one more time the timezone on GMT+0800, you can clean your datetime string with substr like

$dateString = "Mon Jul 07 2014 13:47:03 GMT+0800 (Malay Peninsula Standard Time)";
$dateString = substr($dateString, 0, strpos($dateString, '('));

after remove this you can use DateTime Object like

$date = new DateTime($dateString); //Mon Jul 07 2014 13:47:03 GMT+0800

echo $date->getTimestamp();
Sign up to request clarification or add additional context in comments.

2 Comments

Which function should i use to identify the column to strip?
@user3148070 You could always use string_replace

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.