未来 12 个月的动态日期选项
我确实一直在努力实现以下目标:
<option value="2011-11"><? echo $month[11]?> '11</option>
<option value="2011-12"><? echo $month[12]?> '11</option>
<option value="2012-1"><? echo $month[1]?> '12</option>
<option value="2012-2"><? echo $month[2]?> '12</option>
根据今天的日期,以下内容是动态的:
<option value="YYYY-m"><? echo $month[12]?> 'yy</option>
并在今天之前的 12 个月内重复该过程。
我的 PHP 基础知识取得了一些进步,我承认我需要那些比我更有知识的人的帮助!
它看起来确实很简单,我经常查看 stackoverflow 来解决问题,尽管这一次我花了太多时间却取得了太少的进展。
谁能帮助我完成这个看似简单的挑战!?
谢谢你!!!
I have really been trying hard to achieve the following:
<option value="2011-11"><? echo $month[11]?> '11</option>
<option value="2011-12"><? echo $month[12]?> '11</option>
<option value="2012-1"><? echo $month[1]?> '12</option>
<option value="2012-2"><? echo $month[2]?> '12</option>
Where the following are dynamic according to today's date:
<option value="YYYY-m"><? echo $month[12]?> 'yy</option>
and repeating the process for the following 12 months ahead of today.
I made some progress with my rudimentary knowledge of PHP, I have admitted I need help from those more knowledgeable than myself!
It does look simple and I often look at stackoverflow to solve things though on this occasion I have spent far too much time and made too little progress.
Can anyone give me a hand to this seemingly simple challenge!?
Thank you!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为任何发现问题的人发表评论。
接受的答案是错误的。请参阅此处:
http://www.php.net/manual/en/ function.strtotime.php#107331
使用此代替:
修复为“第一天”
Commenting for anybody who finds question.
The accepted answer is wrong. See here:
http://www.php.net/manual/en/function.strtotime.php#107331
use this instead:
The fix being "first day of"
此片段是概念证明,可准确实现您想要的效果。
如果您想以特定语言打印月份名称,您应该查看 setlocale 并在 date 中使用
F
参数This snippet is proof of concept achieving exactly what you want.
If you want to print the name of the month in your specific language, you should take a look at setlocale and just use the
F
parameter in date干得好:
Here you go: