Through the twitter API I was able to get the datetime of when something was tweeted
Jul 25 17:42:55 +0000 2013
Now, in PHP, how do I get that into standard unix:
2013-6-25 17:42:55
I'm not to sure on anything to deal with datetime but I think there is an easier way to do this rather than having to parse through and change things with str_replace
and substr
Change YYYY-MM-DD to DD-MM-YYYY$newDate = date("d-m-Y", strtotime($orgDate));
Time is represented using a subset of ISO-8601. More specifically, the strptime string for our date format is "%Y-%m-%dT%l:%M:%S%z".
Mysql default date format is Year-Month-Date that is why every PHP developer has with a problem. $date = "2019-02-08" ; $newDate1 = date ( "m-d-Y" , strtotime ( $date )); $newDate2 = date ( "l M, d, Y" , strtotime ( $date ));
Use the DateTime
class, specifically the static createFromFormat()
method
$dt = DateTime::createFromFormat('M j H:i:s P Y', 'Jul 25 17:42:55 +0000 2013');
echo $dt->format('Y-m-d H:i:s');
Working example - http://codepad.viper-7.com/gLdEll
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With