您可以将 strtotime
字符串条件传递给 $faker->dateTimeBetween()
。
//ranging from today ending in 2 years
$faker->dateTimeBetween('+0 days', '+2 years')
//ranging from next week ending in 1 month
$faker->dateTimeBetween('+1 week', '+1 month')
//ranging from next sunday to next wednesday (if today is wednesday)
$faker->dateTimeBetween('next sunday', 'next wednesday')
参见http://php.net/manual/zh/function.strtotime.php,了解完整的字符串用法和组合。
尝试传递Unix时间戳作为$max
:
$unixTimestamp = '1461067200'; // = 2016-04-19T12:00:00+00:00 in ISO 8601
echo $faker->dateTime($unixTimestamp);
echo $faker->date('Y-m-d', $unixTimestamp);
// for all rows
$faker->dateTimeBetween('now', $unixTimestamp);
或者将一个strtotime
时间字符串传递给$faker->dateTimeBetween()
:
// between now and +30y
$faker->dateTimeBetween('now', '+30 years');
$faker->dateTimeBetween('now', '+01 days');
或者对于未来的日期,我们可以使用PHP strtotime
函数,就像@mshaps已经提到的那样。
试试这个:
$faker -> dateTimeThisDecade($max = '+10 years')