最近,我遇到了一个应用程序https://entire.life,该应用程序显示了一个日历,如下面的图片所示,其中显示了您生命中每一年的一排点。
点的行宽为52点,该行年中每周1点。
每行是一年。
每行第一个点星期日期从您生日的那一周开始,而不是从该年的1月1日开始。因此,每周的点是每行1年,从生日那天开始到结束。
下面的最后一张图片显示,今天日期的未来的周点显示为灰色点,表示这些周尚未发生。
这是上面图片中的实时示例,旨在了解实际的效果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,我想根据用户的出生日期(如上面显示的应用程序)生成这样的日历。
这是上面图片中的实时示例,旨在了解实际的效果https://entire.life/jason-davis
规则:
Using PHP's DateTime functions how can I determine the start and end dates for each of the 52 weeks based on a users birth date?
My birthdate in the example here is April 21 1983 The 1st years week dots represent these dates based on that start date:
1st row of year dots
- 21 – 27 Apr 1983 - 0 years old
- 28 Apr – 4 May 1983 - 0 years old
- 5 – 11 May 1983 - 0 years old
- 12 – 18 May 1983 - 0 years old
- 19 – 25 May 1983 - 0 years old
- 26 May – 1 Jun 1983 - 0 years old
- 2 – 8 Jun 1983 - 0 years old
- 9 – 15 Jun 1983 - 0 years old
- 16 – 22 Jun 1983 - 0 years old
- 23 – 29 Jun 1983 - 0 years old
- ...
- ... - ...
- 29 Mar – 4 Apr 1984 - 0 years old
- 5 – 11 Apr 1984 - 0 years old
- 12 – 18 Apr 1984 - 0 years old
- 19 – 20 Apr 1984 - 0 years old
年点第二排
-1984年4月21日至27日1岁-1984年4月28日至5月4日-1岁
- 1984年5月11日至5月11日-1岁
-1984年5月12日至18日-1岁
-5月19日至25日1984 - 1岁以上
- 5月26日- 1984年6月1日- 1岁以上
- 2 - 1984年6月8日- 1岁以上
- 9 - 1984年6月15日- 1岁以上
- 16 - 1984年6月22日- 1岁以上
- 23 - 29 1984年6月-1岁
-...
-...
-...-
1985年3月29日至4月4日-1岁
- 1985年4月5日至11日-1岁
-1985年4月12日至18日-1岁
- 1985年4月19日至20日-1岁
你去了:
<?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
}
}
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句