I am getting json response like this
"created_at"
]=>string(30)"Thu Mar 13 14:24:13 +0000 2014"
I want to extract date, time, month seperately. Is it possible via regex?
UPDATE:
i want date, time month each in seperate variable.
Without testing you could do something like
$response = json_decode(/* json string */);
$dt new DateTime(response->created_at);
$date = $dt->format('m/d/Y');
$time = $dt->format('H:i:s');
$month = $dt->format('m');
This is if your json is valid
Try using DateTime's createFromFormat method. A regex would perform better, but this is a bit easier to read and understand.
$created_at = $thing->created_at;
$date = DateTime::createFromFormat('D M d H:m:s O Y', $created_at); // this might be overly verbose
echo $date->format('Y-m-d'); // 2014-03-13
echo $date->format('H:m:s'); // 14:24:13
Look here to format the dates.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.