如何在 Faker 中获取未来日期

2022-08-30 16:47:36

如何通过以下方式获取未来日期:

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

dateTime($max = 'now')  

即,对于将来的日期时间,$max值应该是多少


答案 1

可以将字符串条件传递给 。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


答案 2

尝试为 以下各项传递 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');

推荐