public static function date2timestamp($date, $format = null)
    {
        $config = Grav::instance()['config'];
        $dateformat = $format ?: $config->get('system.pages.dateformat.default');

        // try to use DateTime and default format
        if ($dateformat) {
            $datetime = \DateTime::createFromFormat($dateformat, $date);
        } else {
            $datetime = new \DateTime($date);
        }

        // fallback to strtotime() if DateTime approach failed
        if ($datetime !== false) {
            return $datetime->getTimestamp();
        }

        return strtotime($date);
    }
public static function date2timestamp($date, $format = null)
    {
        $config = Grav::instance()['config'];
        $dateformat = $format ?: $config->get('system.pages.dateformat.default');

        // try to use DateTime and default format
        if ($dateformat) {
            $datetime = \DateTime::createFromFormat($dateformat, $date);
        } else {
            $datetime = new \DateTime($date);
        }

        // fallback to strtotime() if DateTime approach failed
        if ($datetime !== false) {
            return $datetime->getTimestamp();
        }

        return strtotime($date);
    }
public static function date2timestamp ( $ date , $ format = null ) { $ config = Grav :: instance ( ) [ 'config' ] ; $ dateformat = $ format ? : $ config -> get ( 'system.pages.dateformat.default' ) ; // try to use DateTime and default format if ( $ dateformat ) { $ datetime = \ DateTime :: createFromFormat ( $ dateformat , $ date ) ; } else { $ datetime = new \ DateTime ( $ date ) ; } // fallback to strtotime() if DateTime approach failed if ( $ datetime !== false ) { return $ datetime -> getTimestamp ( ) ; } return strtotime ( $ date ) ; }
Get the timestamp of a date

@param string $date a String expressed in the system.pages.dateformat.default format, with fallback to a
strtotime argument
@param string $format a date format to use if possible
@return int the timestamp
Get the timestamp of a date