Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
587 views
in Technique[技术] by (71.8m points)

php - strtotime 'next month' not acting as expected (today that is)

This is only happening on the 31st so far

echo date('F',strtotime('this month')); //May
echo date('F',strtotime('next month'));//July
echo date('F',strtotime('+1 month'));//July

As far as I understand June comes after May. But i'm guessing php is being lazy in just adding 31 days from now, skipping an entire month.

How can I safely get the next month regardless of lenght? Ideally using strttotime

edit Forgot to mention, why i was hoping to use strtotime is that I'm using a search box to find events interpreting user input strtotime

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The most robust way is probably:

date('F', mktime(0, 0, 0, date('n') + 1, 1))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...