Accepts the same format as the date() function.

@see date(), \DateTime

@param $format

@return string
558208
public function format(string $format)
    {
        $result = '';
        $length = \mb_strlen($format);

        $skip_next = false;

        // iterate for each character
        for ($index = 0; $index < $length; $index++) {
            $format_char = mb_substr($format, $index, 1);

            $result .= $this->getValueOfFormatCharacter($format_char, $skip_next);
        }

        // remove null bits if they exist
        return str_replace("\0", '', $result);
    }
1001274
public function getUpdatedAt($format = 'Y-m-d H:i:s')
    {
        if ($this->updatedAt instanceof \DateTime && $format !== null) {
            return $this->updatedAt->format($format);
        }

        return $this->updatedAt;
    }
636255
protected function date($format){

		$timestamp = $this->getTimestamp();
		
	    list($gYear, $gMonth, $gDay, $gWeek) = explode('-', date('Y-m-d-w', $timestamp));
	    list($pYear, $pMonth, $pDay) = static::getJalali($gYear, $gMonth, $gDay);
	    $pWeek = ($gWeek + 1);

	    if ($pWeek >= 7) {
	        $pWeek = 0;
	    }

	    if ($format == '\\') {
	        $format = '//';
	    }

	    $lenghFormat = strlen($format);
	    $i = 0;
	    $result = '';

	    while ($i < $lenghFormat) {
	        $par = $format{$i};
	        if ($par == '\\') {
	            $result .= $format{ ++$i};
	            $i ++;
	            continue;
	        }
	        switch ($par) {
	            # Day
	            case 'd':
	                $result .= sprintf('%02s', $pDay);
	                break;

	            case 'D':
	                $result .= substr(static::$dayWeek[$pWeek], 0, 2);
	                break;

	            case 'j':
	                $result .= $pDay;
	                break;

	            case 'l':
	                $result .= static::$dayWeek[$pWeek];
	                break;

	            case 'N':
	                $result .= $pWeek + 1;
	                break;

	            case 'w':
	                $result .= $pWeek;
	                break;

	            case 'z':
	                $result .= $this->daysYear($pMonth, $pDay);
	                break;

	            case 'S':
	                $result .= self::NUMBER_TH;
	                break;

	            # Week
	            case 'W':
	                $result .= ceil($this->daysYear($pMonth, $pDay) / 7);
	                break;

	            # Month
	            case 'F':
	                $result .= static::$monthYear[$pMonth-1];
	                break;

	            case 'm':
	                $result .= sprintf('%02s', $pMonth);
	                break;

	            case 'M':
	                $result .= substr(static::$monthYear[$pMonth-1], 0, 6);
	                break;

	            case 'n':
	                $result .= $pMonth;
	                break;

	            case 't':
	                $result .= static::isLeapYear($pYear) && ($pMonth == 12) ? 30 : static::$daysMonthJalali[intval($pMonth)-1];
	                break;

	            # Years
	            case 'L':
	                $result .= intval($this->isLeapYear($pYear));
	                break;

	            case 'Y':
	            case 'o':
	                $result .= $pYear;
	                break;

	            case 'y':
	                $result .= substr($pYear, 2);
	                break;

	            # Time
	            case 'a':
	            case 'A':
	                if (date('a', $timestamp) == 'am') {
	                    $result .= (($par == 'a') ? self::AM : self::ANTE_MERIDIEM);
	                } else {
	                    $result .= (($par == 'a') ? self::PM : self::POST_MERIDIEM);
	                }
	                break;

	            case 'B':
	            case 'g':
	            case 'G':
	            case 'h':
	            case 'H':
	            case 's':
	            case 'u':
	            case 'i':
	            # Timezone
	            case 'e':
	            case 'I':
	            case 'O':
	            case 'P':
	            case 'T':
	            case 'Z':
	                $result .= date($par, $timestamp);
	                break;

	            # Full Date/Time
	            case 'c':
	                $result .= ($pYear . '-' . $pMonth . '-' . $pDay . ' ' . date('H:i:s P', $timestamp));
	                break;

	            case 'r':
	                $result .= (substr(static::$dayWeek[$pWeek], 0, 2) . '، ' . $pDay . ' ' . substr(static::$monthYear[$pMonth], 0, 6) . ' ' . $pYear . ' ' . date('H:i:s P', $timestamp));
	                break;

	            case 'U':
	                $result .= $timestamp;
	                break;

	            default:
	                $result .= $par;
	        }
	        $i ++;
	    }

	    return $result;
	}
437191
public function format($format = '%d/%m/%Y')
    {
        if ($this->time == null) {
            return false;
        }
        
        return strftime($format, $this->time);
    }
18972
public function date($key, $format = "F j, Y")
    {
        if (is_numeric($this->_params[$key])) {
            return date($format, $this->_params[$key]);
        }

        return date($format, strtotime($this->_params[$key]));
    }
804358
public function getRequestDate($format = null)
    {
        $node = $this->getFirst('//epp:epp/epp:response/epp:resData/domain:trnData/domain:reDate');
        if ($format === null) {
            return $node->nodeValue;
        }

        return date_create_from_format($format, $node->nodeValue);
    }
681352
public static function DateFormat($format, $date = null)
  {
    if (!empty($date) && !is_int($date)) {
      $date = strtotime($date);
    }

    return strftime($format, $date ?: time());
  }
653170
public static function validateDateFormat($format)
    {
        $format = str_replace(array_keys(static::$_map['date']), '', $format); // remove placeholders
        $format = preg_replace("/'(.*)'/", '', $format); // remove literals
        $format = preg_replace('/[^a-z]/i', '', $format);
        $format = trim($format);

        return empty($format);
    }
457932
public function formatDate($format, \DateTime $date = null)
    {
        if (null === $date) {
            return null;
        }

        return $date->format($format);
    }
534309
public function getDate($format = null)
    {
        $format = empty($format) ? $this->format : $format;

        return strftime($format, $this->ts);
    }
717796
public function format($format = 'date', $timestamp = null)
    {
        $timestamp = is_numeric($timestamp) ? '@'.intval($timestamp) : $timestamp;
        $timestamp = is_a($timestamp, 'DateTime') ? $timestamp : new DateTime($timestamp);

        $key = $this->getTranslationKey("date.formats.{$format}");
        $format = $this->translator->has($key) ? $this->translator->get($key) : null;

        if (is_null($format)) {
            throw new \InvalidArgumentException('Date format is invalid or does not exists in current language');
        }

        return strftime($format, $timestamp->format('U'));
    }
1161388
public function format($format) {

		if(false === is_string($format)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($format)), E_USER_ERROR);
		}

		$this -> format = $format;

		return $this;
	}
627194
public function format(string $format) : string
    {
        // Replace microseconds first so they become literals.
        // Ignore any escaped microsecond identifiers.
        $format = preg_replace_callback(
            // Starting at the start of the string or the first non % character,
            // consume pairs of % characters (effectively consuming all escaped %s)
            // and finally match the string %u.
            '/((?:^|[^%])(?:%{2})*)(%u)/',
            function (array $matches) {
                return $matches[1] . $this->microseconds;
            },
            $format
        );

        $format = $this->wrapped->format($format);
        
        return $format;
    }
242438
public function setTimeFormat($format) {
        if (is_string($format)) {
            $this->timeFormatter = function ($t) use ($format) {
                return strftime($format, $t);
            };
        } else {
            $this->timeFormatter = $format;
        }

        return $this;
    }
1355491
public static function datetime($value, $format = 'Y-m-d H:i:s')
    {
        if (empty($value)) {
            return null;    
        }
        
        $datetime = new \DateTime($value);

        return $datetime->format($format);
    }
756018
public function format($format)
    {
        $pad    = false;
        $rChar  = 'hmsfHMS';
        $string = $this->format = $format;
        $string = static::encode($string, $rChar);

        // Perform rounding.
        $this->round = static::maxRound($format);

        // Decimal years, weeks, days, hours, minutes, and seconds
        static::fmtRep('Y', $string, $this->years);
        static::fmtRep('W', $string, $this->weeks);
        static::fmtRep('D', $string, $this->days);
        static::fmtRep('H', $string, $this->hours);
        static::fmtRep('M', $string, $this->min);
        static::fmtRep('S', $string, $this->sec);

        // Leading zeros h m s
        $string = str_replace('0h', sprintf('%02d', $this->h), $string);
        $string = str_replace('0m', sprintf('%02d', $this->m), $string);
        $string = str_replace('0s', sprintf('%02d', $this->s), $string);

        // No leading zeros, h m s
        $string = str_replace('h', $this->h, $string);
        $string = str_replace('m', $this->m, $string);
        $string = str_replace('s', $this->s, $string);

        // Fractional seconds.
        if (preg_match_all('/([0-9])f/', $string, $m)) {
            for ($i = 0; $i < count($m[0]); $i++) {
                $f = substr($this->f, 0, $m[1][$i]);

                if ($pad) {
                    $f      = str_pad($f, $m[1][$i], '0');
                    $string = str_replace($m[0][$i], $f, $string);
                } else {
                    if ($f == 0) {
                        $string = str_replace('.' . $m[0][$i], '', $string);
                        $string = str_replace($m[0][$i], '', $string);
                    } else {
                        $string = str_replace($m[0][$i], $f, $string);
                    }
                }
            }
        }

        return static::decode($string, $rChar);
    }
262096
public function format($format) {
        
        // first of all check for convention
        $this->updateJalaliFromGeorgian();
        
        // Find what to replace
        $characters = (preg_match_all('/([a-zA-Z]{1})/', $format, $characters)) ? $characters[0] : [];
        
        // making the replace array
        $replaces = [];
        foreach ($characters as $character) {
            
            switch ($character) {
                
                // Intact ones
                case 'B':
                case 'h':
                case 'H':
                case 'g':
                case 'G':
                case 'i':
                case 's':
                case 'I':
                case 'U':
                case 'u':
                case 'Z':
                case 'O':
                case 'P':
                case 'e':
                case 'T':
                    $replace = $this->carbon->format($character);
                    break;
                
                // Day
                case 'd':
                    $replace = sprintf("%02d", $this->day);
                    break;
                case 'D':
                    $replace = static::getDayName($this->carbon->format('D'), true);
                    break;
                case 'j':
                    $replace = $this->day;
                    break;
                case 'l':
                    $replace = static::getDayName($this->carbon->format('l'));
                    break;
                case 'N':
                    $replace = static::getDayName($this->carbon->format('l'), false, 1, true);
                    break;
                case 'S':
                    $replace = static::t('th');
                    break;
                case 'w':
                    $replace = static::getDayName($this->carbon->format('l'), false, 1, true) - 1;
                    break;
                case 'z':
                    $replace = static::getDayOfYear($this->day, $this->month);
                    break;
                
                // Week
                case 'W':
                    $replace = ceil(static::getDayOfYear($this->day, $this->month) / 7);
                    break;
                
                // Month
                case 'F':
                    $replace = static::getMonthName($this->month);
                    break;
                case 'm':
                    $replace = sprintf("%02d", $this->month);
                    break;
                case 'M':
                    $replace = static::getMonthName($this->month, true);
                    break;
                case 'n':
                    $replace = $this->month;
                    break;
                case 't':
                    $replace = static::getMonthLength($this->month, $this->year);
                    break;
                
                // Year
                case 'L':
                    $replace = static::isLeapYear($this->year, true) ? 1 : 0;
                    break;
                case 'o':
                case 'Y':
                    $replace = $this->year;
                    break;
                case 'y':
                    $replace = $this->year % 100;
                    break;
                
                // Time
                case 'a':
                    $replace = static::t($this->carbon->format('a'));
                    break;
                case 'A':
                    $replace = static::t($this->carbon->format('a'));
                    break;
                
                // Full Dates
                case 'c':
                    $replace = $this->year . '-' .
                               sprintf("%02d", $this->month) . '-' .
                               sprintf("%02d", $this->day) . 'T' .
                               $this->carbon->format('H') . ':' .
                               $this->carbon->format('i') . ':' .
                               $this->carbon->format('s') .
                               $this->carbon->format('P');
                    break;
                case 'r':
                    $replace = static::getDayName($this->carbon->format('D'), true) . ', ' .
                               sprintf("%02d", $this->day) . ' ' .
                               static::getMonthName($this->month, true) . ' ' .
                               $this->year . ' ' .
                               $this->carbon->format('H') . ':' .
                               $this->carbon->format('i') . ':' .
                               $this->carbon->format('s') . ' ' .
                               $this->carbon->format('P');
                    break;
                default:
                    $replace = $character;
            }
            
            //do the replace
            $replaces[$character] = $replace;
            
        }
        
        return strtr($format, $replaces);
    }