截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Time.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Songshenzong\Support;
  3. /**
  4. * Class Time
  5. *
  6. * @package Songshenzong\Support
  7. */
  8. class Time
  9. {
  10. /**
  11. * @param int|string $begin_time
  12. * @param int|string $end_time
  13. *
  14. * @return array
  15. */
  16. public static function dates($begin_time, $end_time = null)
  17. {
  18. if ($end_time === null) {
  19. $end_time = time();
  20. }
  21. // Y-m-d to timestamp
  22. if (!is_int($begin_time)) {
  23. $begin_time = strtotime($begin_time);
  24. }
  25. // Y-m-d to timestamp
  26. if (!is_int($end_time)) {
  27. $end_time = strtotime($end_time);
  28. }
  29. $dates = [];
  30. for ($start = $begin_time; $start <= $end_time; $start += 86400) {
  31. $dates[] = date('Y-m-d', $start);
  32. }
  33. return $dates;
  34. }
  35. /**
  36. * Format Time.
  37. *
  38. * @param string $time_string
  39. *
  40. * @return false|string
  41. */
  42. public static function formatTime($time_string)
  43. {
  44. $time = time() - strtotime($time_string);
  45. $time1 = time() - strtotime('today');
  46. if ($time < 60) {
  47. $str = '刚刚';
  48. } elseif ($time < 3600) {
  49. $min = floor($time / 60);
  50. $str = $min . '分钟前';
  51. } elseif ($time < 24 * 3600) {
  52. $min = floor($time / (60 * 60));
  53. $str = $min . '小时前';
  54. } elseif ($time > $time1 && $time < 7 * 24 * 3600) {
  55. $min = floor($time / (3600 * 24));
  56. $str = $min . '天前';
  57. } else {
  58. $str = date('n月j日 H:i', strtotime($time_string));
  59. }
  60. return $str;
  61. }
  62. }