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

获取当月和上个月的所有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>

图片转代码服务由CSDN问答提供 功能建议

此问题已经存在 这里有一个答案:

  • 在php中获取给定月份和年份的开始和结束unix时间戳 3 answers

    我正在创建一个脚本,我需要在今天,昨天,上个月,本月显示视图。 我能够使用以下代码获取今天和昨天的视图:

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

    我在数据库中的时间戳是unix时间戳。 如何才能获得本月和上个月的观点?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    点赞 打赏 评论

相关推荐 更多相似问题