我如何获得未来的日期:
https://github.com/fzaninotto/Faker#fakerproviderdatetime
dateTime($max = 'now')
即未来日期时间的 $max 值应该是多少
您可以将
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/en/function.strtotime.php 以获取字符串用法和组合的完整列表。
尝试为
$max
传递unix时间戳:
$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')
我不必要的做法:
$currentDate = strtotime(Carbon::now());
$date = rand($currentDate, $currentDate + 31536000); // Between now and 1 year later
$dateFormated = date('Y-m-d H:i:s', $date);