如何在 Faker 中获取未来日期

How to get future date in Faker

如何获得未来的日期:

https://github.com/fzaninotto/Faker#fakerproviderdatetime

dateTime($max = 'now')  

即未来日期时间的 $max 值应该是多少

尝试为 $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');

您可以将 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

试试这个:

$faker -> dateTimeThisDecade($max = '+10 years')

获取明天的日期。我们可以用这个。

$faker->dateTimeBetween('now', '+01 days');

或者对于未来的日期,我们可以使用 php strtotime 函数,正如@mshaps 已经提到的那样。