• This function return me AM/PM hours, but i need to show 24H. How?

    function abs_get_times( $interval = '+30 minutes' ) {
        $output = array();
    
        $current = strtotime( '00:00' );
        $end = strtotime( '23:59' );
        $time_format = get_option( 'time_format' );
    
        while ( $current <= $end ) {
            $time = date_i18n( 'H:i', $current );
            $output[ $time ] = date_i18n( $time_format, $current );
            $current = strtotime( $interval, $current );
        }
    
        return $output;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Can you just use the PHP date function?

    // 12-hour time to 24-hour time 
    $formatDate  = date("H:i", strtotime("08:30 PM"));
    Moderator bcworkz

    (@bcworkz)

    Localized date/times in WP are a little strange. If you do not use WP date/time functions, there’s a risk of either applying a double time zone offset, or not applying it at all. To convert a static time like 8:30 PM, PHP functions are fine. If you want a localized time of a post date use WP functions.

    You’d get 24 hour format with your OP function if your site’s settings were set to 24 hour. It returns date times according to that setting. To override that setting and force 24 hour format, do $time_format = 'H:i';

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problem with AM/PM’ is closed to new replies.