public static create ( integer | null $year = null, integer | null $month = null, integer | null $day = null, integer | null $hour = null, integer | null $minute = null, integer | null $second = null, DateTimeZon\DateTimeZone | string | null $tz = null ) : static | ||
$year | integer | null | The year to create an instance with. |
$month | integer | null | The month to create an instance with. |
$day | integer | null | The day to create an instance with. |
$hour | integer | null | The hour to create an instance with. |
$minute | integer | null | The minute to create an instance with. |
$second | integer | null | The second to create an instance with. |
$tz | DateTimeZon\DateTimeZone | string | null | The DateTimeZone object or timezone name the new instance should use. |
return | static |
public static function create($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $tz = null)
{
$year = $year === null ? date('Y') : $year;
$month = $month === null ? date('n') : $month;
$day = $day === null ? date('j') : $day;
if ($hour === null) {
$hour = date('G');
$minute = $minute === null ? date('i') : $minute;
$second = $second === null ? date('s') : $second;
} else {
$minute = $minute === null ? 0 : $minute;
$second = $second === null ? 0 : $second;
}
$instance = static::createFromFormat('Y-n-j G:i:s', sprintf('%s-%s-%s %s:%02s:%02s', 0, $month, $day, $hour, $minute, $second), $tz);
return $instance->addYears($year);
}