我最近遇到了一个应用程序https://entire.life,它显示了一个日历,如下面的图片,其中显示了你生命中每一年的一排点。
这一行圆点宽52点,每周1点。
每行一年。
每一行第一周开始于你出生的那一周,而不是一年的一月一日。因此,每一行的周点为1年,开始和结束于您的生日周。
下面的最后一张图片显示,未来日期的周点将显示为灰色点,以表示这些周尚未发生。
下面是上面图片中的一个活生生的例子,以查看dit在实际操作中的https://entire.life/jason-davis
https://i.stack.imgur.com/ne07D.png
下面的图像显示了一个窗体,用于为单击的当前周点添加事件。
https://i.stack.imgur.com/K5BUT.png
这张图显示了未来日期的周点是灰色的。
https://i.stack.imgur.com/pYGAn.png
问题
使用PHP,我想根据用户的生日(如上面所示的应用程序)生成这样的日历。
下面是上面图片中的一个活生生的例子,以查看dit在实际操作中的https://entire.life/jason-davis
规则:
使用DateTime函数,如何根据用户的出生日期确定52周中每周的开始日期和结束日期?
在这个例子中,我的生日是1983年4月21日,根据这个开始日期,第一年的周点代表了这些日期:
第一行dots
第2行dots
发布于 2016-11-08 18:32:32
就这样吧:
<?php
$userBirthDate = "1990-10-02"; // You probably use data from database or POST or GET, I setted a static one just for the example
$wishedDate = new DateTime($userBirthDate); // Here, you can add any desired date as an argument to DateTime, by default, it'll take the current DateTime.
// This is for 100 years
for ($x = 0; $x < 100; $x++){
echo '<hr>'; // Just so every year will be separated by a html horizontal bar
$limit = 52; // 52 for a year, but you could do as much as you need right there
for ($i = 0; $i < $limit; $i++){
echo $wishedDate->format('Y-m-d H:i:s'); // Write the current date
echo '<br />'; // Just to switch line
$wishedDate->modify('+1 week'); // Add one week to the wished date
}
}
?>
https://stackoverflow.com/questions/40493968
复制相似问题