如何让一个倒计时的最终值成为新的起始值?
How to make the final value of a countdown become new starting value?
我正在做一个学校项目,我每周跟踪用户的推文频率。我有工作代码,但在每个 1 周周期结束时,我需要手动调整新的起始推文总数和未来一周的日期。
如何实现自动化,使最终推文计数成为新的起始推文计数,并将一周添加到结束日期?我使用下面的代码是朝着正确的方向前进,还是应该将这些最终的推文总值存储在数据库中?谢谢!
// Get current tweet total and calculate current count
$ptTotal = $ptObject->{'statuses_count'};
$ptStart = 572;
$ptCount = ($ptTotal-$ptStart);
// Set end date & convert to EST
$ptdatestr="2017-05-30 12:00:00";
$ptdate=strtotime($ptdatestr)+14400;
// Calculate time remaining
$ptdiff=$ptdate-time();
$ptdays=floor($ptdiff/86400);
$pthours=round(($ptdiff-$ptdays*86400)/3600);
// Re-set start value and add one week to countdown
if ($ptdiff <= 0) {
$ptStart = $ptTotal;
$ptdate = $ptDate + 604800;
}
我要说的是,无论您如何自动化此代码块(请参阅 Alejandro 的评论),您都应该避免使用任何包含 +86400
(或其中一个因素)的方法。当涉及夏令时时,事情会在晚上发生。
相反,我建议您整合 DateTime objects. They are highly versatile and have specific features that will aid you in your specific project. This is a full list of related functions: http://php.net/manual/en/book.datetime.php
实施 Datetime 对象和函数将使您的项目更可靠、更精简。沉浸在上面的 php 手册页和后面的评论中;并继续研究 Whosebug。
关于您的具体问题的更多信息:是的,我认为您的方向是正确的。是的,我想我会将数据存储在数据库中。
祝你好运。
我正在做一个学校项目,我每周跟踪用户的推文频率。我有工作代码,但在每个 1 周周期结束时,我需要手动调整新的起始推文总数和未来一周的日期。
如何实现自动化,使最终推文计数成为新的起始推文计数,并将一周添加到结束日期?我使用下面的代码是朝着正确的方向前进,还是应该将这些最终的推文总值存储在数据库中?谢谢!
// Get current tweet total and calculate current count
$ptTotal = $ptObject->{'statuses_count'};
$ptStart = 572;
$ptCount = ($ptTotal-$ptStart);
// Set end date & convert to EST
$ptdatestr="2017-05-30 12:00:00";
$ptdate=strtotime($ptdatestr)+14400;
// Calculate time remaining
$ptdiff=$ptdate-time();
$ptdays=floor($ptdiff/86400);
$pthours=round(($ptdiff-$ptdays*86400)/3600);
// Re-set start value and add one week to countdown
if ($ptdiff <= 0) {
$ptStart = $ptTotal;
$ptdate = $ptDate + 604800;
}
我要说的是,无论您如何自动化此代码块(请参阅 Alejandro 的评论),您都应该避免使用任何包含 +86400
(或其中一个因素)的方法。当涉及夏令时时,事情会在晚上发生。
相反,我建议您整合 DateTime objects. They are highly versatile and have specific features that will aid you in your specific project. This is a full list of related functions: http://php.net/manual/en/book.datetime.php
实施 Datetime 对象和函数将使您的项目更可靠、更精简。沉浸在上面的 php 手册页和后面的评论中;并继续研究 Whosebug。
关于您的具体问题的更多信息:是的,我认为您的方向是正确的。是的,我想我会将数据存储在数据库中。
祝你好运。