Home  >  Article  >  Backend Development  >  Code that displays the start and end points and timestamp of today, this month, last month, and this year

Code that displays the start and end points and timestamp of today, this month, last month, and this year

WBOY
WBOYOriginal
2016-07-25 09:05:30971browse
  1. /**

  2. Example of comprehensive application of php timestamp
  3. date: 2013/2/19
  4. link: http://bbs.it-home.org
  5. */
  6. $t = time();
  7. $t1 = mktime(0,0,0,date(“m”,$t),date(“d”,$t),date(“Y”,$t));
  8. $t2 = mktime(0,0,0,date(“m”,$t),1,date(“Y”,$t));
  9. $t3 = mktime(0,0,0,date(“m”,$t)-1,1,date(“Y”,$t));
  10. $t4 = mktime(0,0,0,1,1,date(“Y”,$t));
  11. $e1 = mktime(23,59,59,date(“m”,$t),date(“d”,$t),date(“Y”,$t));
  12. $e2 = mktime(23,59,59,date(“m”,$t),date(“t”),date(“Y”,$t));
  13. $e3 = mktime(23,59,59,date(“m”,$t)-1,date(“t”,$t3),date(“Y”,$t));
  14. $e4 = mktime(23,59,59,12,31,date(“Y”,$t));

  15. //测试

  16. echo date(“当前 Y-m-d H:i:s”,$t).” $t
    ”;
  17. echo date(“今天起点 Y-m-d H:i:s”,$t1).” $t1
    ”;
  18. echo date(“今月起点 Y-m-d H:i:s”,$t2).” $t2
    ”;
  19. echo date(“上月起点 Y-m-d H:i:s”,$t3).” $t3
    ”;
  20. echo date(“今年起点 Y-m-d H:i:s”,$t4).” $t4
    ”;
  21. //测试
  22. echo date(“今天终点 Y-m-d H:i:s”,$e1).” $e1
    ”;
  23. echo date(“今月终点 Y-m-d H:i:s”,$e2).” $e2
    ”;
  24. echo date(“上月终点 Y-m-d H:i:s”,$e3).” $e3
    ”;
  25. echo date(“今年终点 Y-m-d H:i:s”,$e4).” $e4
    ”;
  26. ?>

复制代码

输出结果: 当前 2011-05-24 15:42:55 1306222975 今天起点 2011-05-24 00:00:00 1306166400 今月起点 2011-05-01 00:00:00 1304179200 上月起点 2011-04-01 00:00:00 1301587200 今年起点 2011-01-01 00:00:00 1293811200 今天终点 2011-05-24 23:59:59 1306252799 今月终点 2011-05-31 23:59:59 1306857599 上月终点 2011-04-30 23:59:59 1304179199 今年终点 2011-12-31 23:59:59 1325347199



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn