Countdown.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. if(!defined('APP_KEY')) { exit('Access Denied'); }
  3. /**
  4. * Suco_Helper_Countdown 倒计时
  5. *
  6. * @version 3.0 2009/09/01
  7. * @author Eric Yu (blueflu@live.cn)
  8. * @copyright Copyright (c) 2009, Suconet, Inc.
  9. * @package Helper
  10. * @license http://www.suconet.com/license
  11. * -----------------------------------------------------------
  12. */
  13. class Helper_Countdown implements Suco_Helper_Interface
  14. {
  15. public static function callback($args)
  16. {
  17. return self::countdown($args[0], $args[1], $args[2]);
  18. }
  19. public static function countdown($endTime, $now = 0, $full = 0)
  20. {
  21. $string = null;
  22. if (!$now) {
  23. $now = time();
  24. }
  25. $s = $endTime - $now;
  26. if ($s >= 60) {
  27. $i = $s / 60;
  28. $s = $s % 60;
  29. if ($i >= 60) {
  30. $h = $i / 60;
  31. $i = $i % 60;
  32. if ($h >= 24) {
  33. $d = $h / 24;
  34. $h = $h % 24;
  35. if ($d >= 30) {
  36. $m = $d / 30;
  37. $d = $d % 30;
  38. if ($m >= 12) {
  39. $y = $m / 12;
  40. $m = $m % 12;
  41. }
  42. }
  43. }
  44. }
  45. }
  46. $return = array();
  47. if (isset($y) && $y > 0) {
  48. $return[] = intval($y) . ' 年' . ($y > 1 ? '' : null);
  49. }
  50. if (isset($m) && $m > 0) {
  51. $return[] = intval($m) . ' 月' . ($m > 1 ? '' : null);
  52. }
  53. if (isset($d) && $d > 0) {
  54. $return[] = intval($d) . ' 天' . ($d > 1 ? '' : null);
  55. }
  56. if (isset($h) && $h > 0) {
  57. $return[] = intval($h) . ' 小时' . ($h > 1 ? '' : null);
  58. }
  59. if (isset($i) && $i > 0) {
  60. $return[] = intval($i) . ' 分钟' . ($i > 1 ? '' : null);
  61. }
  62. if (isset($s) && $s > 0) {
  63. $return[] = intval($s) . ' 秒' . ($s > 1 ? '' : null);
  64. }
  65. if ($return) {
  66. if ($full) {
  67. return implode(' ', $return);
  68. } else {
  69. return $return[0] . ' ' . @$return[1];
  70. }
  71. } else {
  72. return '已过期';
  73. }
  74. }
  75. }