/ Published in: PHP

Timestamp2array
Convert a timestamp (20120525
) to a date (2012-05-25
), you can specify the format in the second parameter.
Expand |
Embed | Plain Text
/** * Convert a timestamp (number) to a date * * @param mixed $timestamp A timestamp i.e. 20120525 * @param string $format The format of the date * * @return string */ function timestamp2date($timestamp, $format = 'Y-m-d') { $date = new Datetime($year.'-'.$month.'-'.$day); return $date->format($format); } /* Example * ======= */ $timestamp = 20120525; $date = timestamp2date($timestamp); // 2012-05-25
You need to login to post a comment.