如何在Faker中获取未来日期

28

1
明天 - Alex Chorry
4个回答

58

您可以将 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,了解完整的字符串用法和组合。


39

尝试传递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');

3
获取明天的日期,我们可以使用以下代码:
$faker->dateTimeBetween('now', '+01 days');

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


0

试试这个:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接