jDateTime::mktime PHP Method

mktime() public static method

Creates a Unix Timestamp (Epoch Time) based on given parameters works like php's built in mktime() function. e.g: $time = $obj->mktime(0,0,0,2,10,1368); $obj->date("Y-m-d", $time); //Format and Display $obj->date("Y-m-d", $time, false, false); //Display in Gregorian ! You can force gregorian mktime if system default is jalali and you need to create a timestamp based on gregorian date $time2 = $obj->mktime(0,0,0,12,23,1989, false);
Author: Sallar Kaboli
public static mktime ( $hour, $minute, $second, $month, $day, $year, $jalali = null, $timezone = null ) : integer
$hour int Hour based on 24 hour system
$minute int Minutes
$second int Seconds
$month int Month Number
$day int Day Number
$year int Four-digit Year number eg. 1390
$jalali bool (Optional) pass false if you want to input gregorian time
$timezone string (Optional) acceps an optional timezone if you want one
return integer Unix Timestamp (Epoch Time)
    public static function mktime($hour, $minute, $second, $month, $day, $year, $jalali = null, $timezone = null)
    {
        //Defaults
        $month = intval($month) == 0 ? self::date('m') : $month;
        $day = intval($day) == 0 ? self::date('d') : $day;
        $year = intval($year) == 0 ? self::date('Y') : $year;
        $hour = intval($hour);
        $minute = intval($minute);
        $second = intval($second);
        //Convert to Gregorian if necessary
        if ($jalali === true || $jalali === null && self::$jalali === true) {
            list($year, $month, $day) = self::toGregorian($year, $month, $day);
        }
        //Create a new object and set the timezone if available
        $date = $year . '-' . sprintf('%02d', $month) . '-' . sprintf('%02d', $day) . ' ' . $hour . ':' . $minute . ':' . $second;
        if (self::$timezone != null || $timezone != null) {
            $obj = new DateTime($date, new DateTimeZone($timezone != null ? $timezone : self::$timezone));
        } else {
            $obj = new DateTime($date);
        }
        //Return
        return $obj->format('U');
    }

Usage Example

Beispiel #1
0
 public static function mktime($hour, $minute, $second, $month, $day, $year, $jalali = null, $timezone = null)
 {
     return jDateTime::mktime($hour, $minute, $second, $month, $day, $year, $jalali, $timezone);
 }
All Usage Examples Of jDateTime::mktime