PHP Zend date format

后端 未结 6 1638
粉色の甜心
粉色の甜心 2021-02-19 08:12

I want to input a timestamp in below format to the database.

yyyy-mm-dd hh:mm:ss

How can I get in above format?

When I

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-19 08:29

    This is how i did it:

    abstract class App_Model_ModelAbstract extends Zend_Db_Table_Abstract
    {
    
        const DATE_FORMAT = 'yyyy-MM-dd';
    
        public static function formatDate($date, $format = App_Model_ModelAbstract::DATE_FORMAT)
        {
            if (!$date instanceof Zend_Date && Zend_Date::isDate($date)) {
                $date = new Zend_Date($date);
            }
    
            if ($date instanceof Zend_Date) {
                return $date->get($format);
            }
    
            return $date;
        }
    }
    

    this way you don't need to be concerned with whether or not its actually an instance of zend date, you can pass in a string or anything else that is a date.

提交回复
热议问题