public function localeDateTime($dateTime, $format = '%B %e, %Y %H:%M', $locale = 0)
    {
        if (!$dateTime instanceof \DateTime) {
            $dateTime = new \DateTime($dateTime);
        }

        // Check for Windows to find and replace the %e modifier correctly
        // @see: http://php.net/strftime
        $os = strtoupper(substr(PHP_OS, 0, 3));
        $format = $os !== 'WIN' ? $format : preg_replace('#(?<!%)((?:%%)*)%e#', '\1%#d', $format);

        // According to http://php.net/manual/en/function.setlocale.php manual
        // if the second parameter is "0", the locale setting is not affected,
        // only the current setting is returned.
        $result = setlocale(LC_ALL, $locale);

        if ($result === false) {
            // This shouldn't occur, but.. Dude!
            // You ain't even got locale or English on your platform??
            // Various things we could do. We could fail miserably, but a more
            // graceful approach is to use the datetime to display a default
            // format
            $this->systemLogger->error('No valid locale detected. Fallback on DateTime active.', ['event' => 'system']);

            return $dateTime->format('Y-m-d H:i:s');
        }
        $timestamp = $dateTime->getTimestamp();

        return strftime($format, $timestamp);
    }
public function localeDateTime($dateTime, $format = '%B %e, %Y %H:%M', $locale = 0)
    {
        if (!$dateTime instanceof \DateTime) {
            $dateTime = new \DateTime($dateTime);
        }

        // Check for Windows to find and replace the %e modifier correctly
        // @see: http://php.net/strftime
        $os = strtoupper(substr(PHP_OS, 0, 3));
        $format = $os !== 'WIN' ? $format : preg_replace('#(?<!%)((?:%%)*)%e#', '\1%#d', $format);

        // According to http://php.net/manual/en/function.setlocale.php manual
        // if the second parameter is "0", the locale setting is not affected,
        // only the current setting is returned.
        $result = setlocale(LC_ALL, $locale);

        if ($result === false) {
            // This shouldn't occur, but.. Dude!
            // You ain't even got locale or English on your platform??
            // Various things we could do. We could fail miserably, but a more
            // graceful approach is to use the datetime to display a default
            // format
            $this->systemLogger->error('No valid locale detected. Fallback on DateTime active.', ['event' => 'system']);

            return $dateTime->format('Y-m-d H:i:s');
        }
        $timestamp = $dateTime->getTimestamp();

        return strftime($format, $timestamp);
    }
public function localeDateTime ( $ dateTime , $ format = '%B %e, %Y %H:%M' , $ locale = 0 ) { if ( ! $ dateTime instanceof \ DateTime ) { $ dateTime = new \ DateTime ( $ dateTime ) ; } // Check for Windows to find and replace the %e modifier correctly // @see: http://php.net/strftime $ os = strtoupper ( substr ( PHP_OS , 0 , 3 ) ) ; $ format = $ os !== 'WIN' ? $ format : preg_replace ( '#(?<!%)((?:%%)*)%e#' , '\1%#d' , $ format ) ; // According to http://php.net/manual/en/function.setlocale.php manual // if the second parameter is "0", the locale setting is not affected, // only the current setting is returned. $ result = setlocale ( LC_ALL , $ locale ) ; if ( $ result === false ) { // This shouldn't occur, but.. Dude! // You ain't even got locale or English on your platform?? // Various things we could do. We could fail miserably, but a more // graceful approach is to use the datetime to display a default // format $ this -> systemLogger -> error ( 'No valid locale detected. Fallback on DateTime active.' , [ 'event' => 'system' ] ) ; return $ dateTime -> format ( 'Y-m-d H:i:s' ) ; } $ timestamp = $ dateTime -> getTimestamp ( ) ; return strftime ( $ format , $ timestamp ) ; }
Returns the date time in a particular format. Takes the locale into
account.

@param string|\DateTime $dateTime
@param string           $format

@return string Formatted date and time
Returns the date time in a particular format . Takes the locale into account .