time() 函数数学
我正在使用 time() 将日期存储在数据库中。 我有某种广告网站。 用户提交他们的广告以及他们希望展示广告的天数,例如:
标题:广告标题....
持续时间:20天
创建日期:time()(当我 在数据库上提交此广告。 )
我需要计算每个广告的纪元格式的到期日期。
exp_date = creation date + 20 days ; /// this line is hypothetical , i need correct way to calculate exp_Date
sql->set(experation date = exp_date);
我还需要知道距离到期日期还剩多少时间(以天、小时和分钟为单位),并将其显示在页面上。
$current time = time();
$remaining_time = $current time - $exp date ; //this line is hypothetical , i need correct way to calculate remaining_time
echo 'remaining time : '.$remaining_time ;
最后我不想显示过期的广告(我不确定最好的方法是计算我显示广告的时间,也许我可以在 20 天后自动禁用广告状态?)
current date = time();
if (ads experation date > current date ) // this line is hypothetical , i need to calculate this
sql->update ('set ads status= 0');
echo 'this ad has been expires ';
exit;
I'm using time() to store date in the database.
I have some kind of advertising web site.
Users submit their ads and number of the days they want their ads to be shown for example:
title : ad title....
duration : 20 days
creation date : time() (I get the creation date by time() when I'm
submitting this ad on the database. )
I need to calculate expiration date for each ad on epoch format.
exp_date = creation date + 20 days ; /// this line is hypothetical , i need correct way to calculate exp_Date
sql->set(experation date = exp_date);
Also I need to know how much time is left to the exp date in days and hours and minutes and show it on the page.
$current time = time();
$remaining_time = $current time - $exp date ; //this line is hypothetical , i need correct way to calculate remaining_time
echo 'remaining time : '.$remaining_time ;
At last I don't want to show expired ads (I'm not sure the best way to do this is to calculate time when I'm showing the ads maybe I could somehow automatically disable ads status after 20 days?)
current date = time();
if (ads experation date > current date ) // this line is hypothetical , i need to calculate this
sql->update ('set ads status= 0');
echo 'this ad has been expires ';
exit;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
计算到期日期:
要计算剩余时间,您应该执行类似
$daysLeft
、$hoursLeft
、$minesLeft
和的操作$seconds
是您想要的值To calculate the expiration date:
To calculate the time left, you should do something like
$daysLeft
,$hoursLeft
,$minutesLeft
and$seconds
are the values that you want你知道一分钟有多少秒吗?小时中的分钟又如何呢?一天几小时?
是什么让你无法将这些数字相乘?
不要显示它们。这就是 SQL 的用途。
哪里 exp_date > unix_timestamp()
将仅选择实际广告。Do you happen to know how the number of seconds in one minute? What about minutes in hour? Hours in a day?
what makes you unable to multiply these numbers?
don't show them. this is what SQL for.
WHERE exp_date > unix_timestamp()
will select only actual ads.为什么不通过每天运行一次脚本(
cron
将执行此操作)来让生活变得简单,并通过这些广告删除(或移动)它们呢?Why not make life simple by running a script once a day (
cron
will do this) and do through those ads an delete (or move) them?