public function setDate($date, $format = DATE_FORMAT_ISO)
    {
        $regex = '/^(\d{4})-?(\d{2})-?(\d{2})([T\s]?(\d{2}):?(\d{2}):?(\d{2})(\.\d+)?(Z|[\+\-]\d{2}:?\d{2})?)?$/i';

        if (preg_match($regex, $date, $regs) && $format != DATE_FORMAT_UNIXTIME) {
            $this->year         = $regs[1];
            $this->month        = $regs[2];
            $this->day          = $regs[3];
            $this->hour         = isset($regs[5]) ? $regs[5] : 0;
            $this->minute       = isset($regs[6]) ? $regs[6] : 0;
            $this->second       = isset($regs[7]) ? $regs[7] : 0;
            $this->partsecond   = (float) isset($regs[8]) ? $regs[8] : 0;
        } elseif (is_numeric($date)) {
            // UNIXTIME
            $this->setDate(date('Y-m-d H:i:s', $date));
        } else {
            // unknown format
            $this->year         = 0;
            $this->month        = 1;
            $this->day          = 1;
            $this->hour         = 0;
            $this->minute       = 0;
            $this->second       = 0;
            $this->partsecond   = (float)0;
        }

        return $this;
    }
public function setDate($date, $format = DATE_FORMAT_ISO)
    {
        $regex = '/^(\d{4})-?(\d{2})-?(\d{2})([T\s]?(\d{2}):?(\d{2}):?(\d{2})(\.\d+)?(Z|[\+\-]\d{2}:?\d{2})?)?$/i';

        if (preg_match($regex, $date, $regs) && $format != DATE_FORMAT_UNIXTIME) {
            $this->year         = $regs[1];
            $this->month        = $regs[2];
            $this->day          = $regs[3];
            $this->hour         = isset($regs[5]) ? $regs[5] : 0;
            $this->minute       = isset($regs[6]) ? $regs[6] : 0;
            $this->second       = isset($regs[7]) ? $regs[7] : 0;
            $this->partsecond   = (float) isset($regs[8]) ? $regs[8] : 0;
        } elseif (is_numeric($date)) {
            // UNIXTIME
            $this->setDate(date('Y-m-d H:i:s', $date));
        } else {
            // unknown format
            $this->year         = 0;
            $this->month        = 1;
            $this->day          = 1;
            $this->hour         = 0;
            $this->minute       = 0;
            $this->second       = 0;
            $this->partsecond   = (float)0;
        }

        return $this;
    }
public function setDate ( $ date , $ format = DATE_FORMAT_ISO ) { $ regex = '/^(\d{4})-?(\d{2})-?(\d{2})([T\s]?(\d{2}):?(\d{2}):?(\d{2})(\.\d+)?(Z|[\+\-]\d{2}:?\d{2})?)?$/i' ; if ( preg_match ( $ regex , $ date , $ regs ) && $ format != DATE_FORMAT_UNIXTIME ) { $ this -> year = $ regs [ 1 ] ; $ this -> month = $ regs [ 2 ] ; $ this -> day = $ regs [ 3 ] ; $ this -> hour = isset ( $ regs [ 5 ] ) ? $ regs [ 5 ] : 0 ; $ this -> minute = isset ( $ regs [ 6 ] ) ? $ regs [ 6 ] : 0 ; $ this -> second = isset ( $ regs [ 7 ] ) ? $ regs [ 7 ] : 0 ; $ this -> partsecond = ( float ) isset ( $ regs [ 8 ] ) ? $ regs [ 8 ] : 0 ; } elseif ( is_numeric ( $ date ) ) { // UNIXTIME $ this -> setDate ( date ( 'Y-m-d H:i:s' , $ date ) ) ; } else { // unknown format $ this -> year = 0 ; $ this -> month = 1 ; $ this -> day = 1 ; $ this -> hour = 0 ; $ this -> minute = 0 ; $ this -> second = 0 ; $ this -> partsecond = ( float ) 0 ; } return $ this ; }
Set the fields of a Date object based on the input date and format

Set the fields of a Date object based on the input date and format,
which is specified by the DATE_FORMAT_* constants.

@param   string  $date input date
@param   int     $format Optional format constant (DATE_FORMAT_*) of the input date.
This parameter isn't really needed anymore, but you could
use it to force DATE_FORMAT_UNIXTIME.
@return AnDate
Set the fields of a Date object based on the input date and format