dousi4257 2014-02-11 20:05
浏览 151
已采纳

获取当月和上个月的所有unix时间戳[重复]

This question already has an answer here:

I am making a script in which I require views to displayed in today, yesterday, last month, this month. I was able to get views for today and yesterday using the following code:

$hour = 12;

$today_count = strtotime("$hour:00:00");
$yest_count = strtotime('-1 day', $today_count);

My timestamp in database is unix timestamp . How can i achieve to get this month and last month views?

</div>
  • 写回答

1条回答 默认 最新

  • doushan1850 2014-02-11 20:22
    关注

    The unix timestamp started on 1 January 1970 and counts the seconds since then. To get the time stamp from 7 days ago you need to know how many seconds that is. eg.

    7(days)*24(hours)60(min)(60 sec) = 604,800

    From there you can subtract that from the current timestamp.

    time() - 604,800 = time stamp from 7 days ago.

    This method will work for any time in the past up until 1 January 1970. Once that is done you can convert that timestamp into any date formate you need.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有偿求qftp工具。能连接,下载文件,发送代码,windows环境,最好qt6 要qt creator写的
  • ¥70 刚刚看到一个人的网站居然是通过cname访问的
  • ¥15 Attributeerror:super object has no attribute '__sklearn_tags__'_'
  • ¥15 逆置单链表输出不完整
  • ¥15 宇视vms-B200-A16@R启动不了,如下图所示,在软件工具搜不到,如何解决?(操作系统-linux)
  • ¥500 寻找一名电子工程师完成pcb主板设计(拒绝AI生成式答案)
  • ¥15 关于#mysql#的问题:UNION ALL(相关搜索:sql语句)
  • ¥15 matlab二位可视化能否针对不同数值范围分开分级?
  • ¥15 已经创建了模拟器但是不能用来运行app 怎么办😭自己搞两天了
  • ¥15 关于#极限编程#的问题,请各位专家解答!