Carbon Data Missing

http://laravel.com/

http://kejyun.github.io/Laravel-4-Docum ... roduction/
回覆文章
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

Carbon Data Missing

文章 yehlu »

https://stackoverflow.com/questions/349 ... ta-missing


tl;dr

Your date string and your date format is different, you have to change the format string or modify the date string so they match.

Explanation

The Problem

This error arises when Carbon's createFromFormat function receieves a date string that doesn't match the passed format string. More precisely this comes from the DateTime::createFromFormat function, because Carbon just calls that:

public static function createFromFormat($format, $time, $tz = null)
{
if ($tz !== null) {
$dt = parent::createFromFormat($format, $time, static::safeCreateDateTimeZone($tz));
} else {
$dt = parent::createFromFormat($format, $time); // Where the error happens.
}

if ($dt instanceof DateTime) {
return static::instance($dt);
}

$errors = static::getLastErrors();
throw new InvalidArgumentException(implode(PHP_EOL, $errors['errors'])); // Where the exception was thrown.
}
Not enough data

If your date string is "shorter" than the format string like in this case:

Carbon::createFromFormat('Y-m-d H:i:s', '2017-01-04 00:52');
Carbon will throw:

InvalidArgumentException in Carbon.php line 425:
Data missing
Too much data

If your date string is "longer" than the format string like in this case:

Carbon::createFromFormat('Y-m-d H:i', '2017-01-02 00:27:00');
Carbon will throw:

InvalidArgumentException in Carbon.php line 425:
Trailing data
回覆文章

回到「laravel」