PHP date Mktime Strtotime Get Time method

Source: Internet
Author: User
Tags echo date
PHP date Mktime Strtotime Get Time method
  1. /**
  2. * Get an array of system years
  3. */
  4. function Getsystemyeararr () {
  5. $year _arr = Array (' + ' + ') ', ' + ' ' + ', ' ' + ', ' ' ' ' ' ', ' ' ' ' + ' 2014 ', ' + ' = ' + ', ' + ' + ', ' ' ~ ' and ' ', ' 2018 ' = ' 2018 ', ' 2019 ' and ' 2019 ', ' 2020 ' and ' 2020 ');
  6. return $year _arr;
  7. }
  8. /**
  9. * Get System Month array
  10. */
  11. function Getsystemmontharr () {
  12. $month _arr = Array (' 1 ' = ' ~ ', ' 2 ' = ' + '), ' 3 ' = ' ", ' 4 ' = '", ' 5 ' = ' ', ' 6 ' + ' ', ' 7 ' = ' 07 ', ' 8 ' + ', ' 9 ' = '-' ', ' ' + ', ' + ', ' one ' and ' one ', ' one ', ' 12 ';
  13. return $month _arr;
  14. }
  15. /**
  16. * Get System Week array
  17. */
  18. function Getsystemweekarr () {
  19. $week _arr = Array (' 1 ' = ' Monday ', ' 2 ' = ' Tuesday ', ' 3 ' = ' Wednesday ', ' 4 ' + ' Thursday ', ' 5 ' + ' Friday ', ' 6 ' = ' Saturday ', ' 7 ' = ' + ' Sunday ');
  20. return $week _arr;
  21. }
  22. /**
  23. * Get the last day of a month
  24. */
  25. function Getmonthlastday ($year, $month) {
  26. $t = mktime (0, 0, 0, $month + 1, 1, $year);
  27. $t = $t-60 * 60 * 24;
  28. return $t;
  29. }
  30. /**
  31. * Get the week array of the system month, the first week insufficient need to complement
  32. */
  33. function Getmonthweekarr ($current _year, $current _month) {
  34. The first day of the month
  35. $firstday = Strtotime ($current _year. '-'. $current _month. '-01 ');
  36. A few days in the first week of the month
  37. $firstweekday = (7-date (' N ', $firstday) + 1);
  38. Calculate the time of the first Monday of the month
  39. $starttime = $firstday -3600*24* (7-$firstweekday);
  40. The last day of the month
  41. $lastday = Strtotime ($current _year. '-'. $current _month. ' -01 '. "+1 month-1 Day");
  42. The last week of the month is a few days
  43. $lastweekday = Date (' N ', $lastday);
  44. Time of the last weekend of the month
  45. $endtime = $lastday -3600*24* $lastweekday;
  46. $step = 3600*24*7;//Step value
  47. $week _arr = Array ();
  48. for ($i = $starttime; $i < $endtime; $i = $i +3600*24*7) {
  49. $week _arr[] = array (' key ' =>date (' y-m-d ', $i). ' | '. Date (' y-m-d ', $i +3600*24*6), ' Val ' =>date (' y-m-d ', $i). ' ~ '. Date (' y-m-d ', $i +3600*24*6));
  50. }
  51. return $week _arr;
  52. }
  53. /**
  54. * Get start and end times for the week
  55. */
  56. function getweek_sdateandedate ($current _time) {
  57. $current _time = strtotime (Date (' y-m-d ', $current _time));
  58. $return _arr[' sdate '] = date (' y-m-d ', $current _time-86400* (date (' N ', $current _time)-1));
  59. $return _arr[' edate ') = Date (' y-m-d ', $current _time+86400* (7-date (' N ', $current _time));
  60. return $return _arr;
  61. }
  62. Query the day, the first 3 days, this week, this month, this year's time
  63. echo Date ("Y-m-d", mktime (0, 0, 0,date ("M"), Date ("D"), date ("Y")) -86400*3); Current date pushed forward 3 days
  64. thinkphp Check the day, this week, this month, this year's time
  65. $time =i (' get.time ');
  66. Switch ($time) {
  67. Case ' Day ':
  68. $startTime =date ("y-m-d");
  69. $endTime =date ("y-m-d");
  70. Break
  71. Case ' Week ':
  72. $startTime =date ("y-m-d", mktime (0, 0, 0,date ("M"), Date ("D")-date ("W") +1,date ("Y")));
  73. $endTime =date ("y-m-d", Mktime (23,59,59,date ("M"), Date ("D")-date ("W") +7,date ("Y")));
  74. Break
  75. Case ' Month ':
  76. $startTime = Date ("y-m-d", mktime (0, 0, 0,date ("M"), 1,date ("Y")));
  77. $endTime =date ("y-m-d", Mktime (23,59,59,date ("M"), Date ("T"), Date ("Y")));
  78. Break
  79. Case ' Year ':
  80. $startTime =date ("Y"). ' -01-01 ';
  81. $endTime =date ("Y"). ' -12-31 ';
  82. Break
  83. Default
  84. Break
  85. }
  86. Other ways to get PHP get last week, this week, last month, this month, this quarter, last quarter time method Daquan
  87. echo Date ("Ymd", Strtotime ("Now"), "\ n";
  88. echo Date ("Ymd", Strtotime ("1 week Monday")), "\ n";
  89. echo Date ("Ymd", Strtotime ("1 week Sunday")), "\ n";
  90. echo Date ("Ymd", Strtotime ("+0 Week Monday")), "\ n";
  91. echo Date ("Ymd", Strtotime ("+0 Week Sunday")), "\ n";
  92. echo "********* months:";
  93. echo Date (' n ');
  94. echo "********* Week of the week:";
  95. Echo Date ("W");
  96. echo "********* Days of the Month:";
  97. echo Date ("T");
  98. echo "*********";
  99. Echo '
    Last week start time:
    ';
  100. echo Date ("Y-m-d h:i:s", mktime (0, 0, 0,date ("M"), Date ("D")-date ("W") +1-7,date ("Y")), "\ n";
  101. echo Date ("Y-m-d h:i:s", Mktime (23,59,59,date ("M"), Date ("D")-date ("W") +7-7,date ("Y")), "\ n";
  102. Echo '
    Starting time of the week:
    ';
  103. echo Date ("Y-m-d h:i:s", mktime (0, 0, 0,date ("M"), Date ("D")-date ("W") +1,date ("Y")), "\ n";
  104. echo Date ("Y-m-d h:i:s", Mktime (23,59,59,date ("M"), Date ("D")-date ("W") +7,date ("Y")), "\ n";
  105. Echo '
    Last month start time:
    ';
  106. echo Date ("Y-m-d h:i:s", mktime (0, 0, 0,date ("M") -1,1,date ("Y")), "\ n";
  107. echo Date ("Y-m-d h:i:s", Mktime (23,59,59,date ("M"), 0,date ("Y")), "\ n";
  108. Echo '
    Starting time of the month:
    ';
  109. echo Date ("Y-m-d h:i:s", mktime (0, 0, 0,date ("M"), 1,date ("Y")), "\ n";
  110. echo Date ("Y-m-d h:i:s", Mktime (23,59,59,date ("M"), Date ("T"), Date ("Y")), "\ n";
  111. $season = Ceil ((date (' n '))/3);//The month of the first quarter
  112. Echo '
    Starting time of the quarter:
    ';
  113. echo Date (' y-m-d h:i:s ', mktime (0, 0, 0, $season *3-3+1,1,date (' Y ')), "\ n";
  114. echo Date (' y-m-d h:i:s ', Mktime (23,59,59, $season *3,date (' t ', mktime (0, 0, 0, $season *3,1,date ("y"))), date (' Y ')), "\ n" ;
  115. $season = Ceil ((date (' n '))/3) -1;//quarter of last quarter
  116. Echo '
    Last quarter start time:
    ';
  117. echo Date (' y-m-d h:i:s ', mktime (0, 0, 0, $season *3-3+1,1,date (' Y ')), "\ n";
  118. echo Date (' y-m-d h:i:s ', Mktime (23,59,59, $season *3,date (' t ', mktime (0, 0, 0, $season *3,1,date ("y"))), date (' Y ')), "\ n" ;
Copy Code
Date, PHP, Strtotime
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.