简体   繁体   English

用户的php动态日期

[英]php dynamic date for user

Hello to all the experts here. 在这里向所有专家问好。

I have a conceptual question that I can use some help with. 我有一个概念性的问题,可以帮助您。

In our site, we allow users to join a group for a specific amount of time. 在我们的网站中,我们允许用户加入特定时间段的群组。 So there is a group that has activities outlined as follows week0day1, week0day4, week1day2, week1day5, week2day3. 因此,有一个小组,其活动概述如下week0day1,week0day4,week1day2,week1day5,week2day3。 In these groups we allow users to join and leave as they would like so week0day1 is not necessarily the same for each user. 在这些组中,我们允许用户加入和退出,因此每个用户的week0day1不一定相同。

I have worked out which week a user is currently in by looking at the date that they joined the group and then doing some math from there, that's not my problem. 通过查看用户加入小组的日期,然后从那里进行一些数学运算,可以算出用户当前所在的星期,这不是我的问题。 My issue comes from how I translate which day of the week an activity on a day like week0day4 would fall out on. 我的问题来自于我如何翻译一周中哪一天(如week0day4)发生的活动。

I thought about using the day of the week the user joined the group as an offset but I am not sure if that is the correct way to deal with this as there might be issues when the offset creates a situation where the calculated day of the week is not actually a valid weekday. 我考虑过使用用户加入组的星期几作为偏移量,但是我不确定这是否是正确的处理方式,因为偏移量可能会导致计算周几的情况出现问题实际上不是有效的工作日。

Can anyone recommend a better solution? 谁能推荐一个更好的解决方案?

Thanks! 谢谢!

Don't reinvent the wheel, this already exists in PHP 不要重新发明轮子,这已经存在于PHP中

http://php.net/manual/en/book.datetime.php http://php.net/manual/zh/book.datetime.php

Given a date you can work out the Day, Tuesday, Wednesday etc. Its always better to work in the standard date time classes. 给定日期,您可以计算出Day,星期二,星期三等。在标准日期时间类中工作总是更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM