选择语言 :

 Core_Date::hours

Number of hours in a day. Typically used as a shortcut for generating a list that can be used in a form.

$hours = Date::hours(); // 01, 02, 03, ..., 10, 11, 12

array Core_Date::hours( [ integer $step = integer 1 , boolean $long = bool false , integer $start = null ] )

参数列表

参数 类型 描述 默认值
$step integer Amount to increment each step by integer 1
$long boolean Use 24-hour time bool false
$start integer The hour to start at null
返回值
  • array A mirrored (foo => foo) array from start-12 or start-23.
File: ./core/classes/date.class.php
public static function hours($step = 1, $long = FALSE, $start = NULL)
{
    // Default values
    $step = (int)$step;
    $long = (bool)$long;
    $hours = array();

    // Set the default start if none was specified.
    if ( $start === NULL )
    {
        $start = ($long === FALSE) ? 1 : 0;
    }

    $hours = array();

    // 24-hour time has 24 hours, instead of 12
    $size = ($long === TRUE) ? 23 : 12;

    for( $i = $start; $i <= $size; $i += $step )
    {
        $hours[$i] = (string)$i;
    }

    return $hours;
}