Time.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. /**
  8. * Description of Time
  9. *
  10. * @author jgao
  11. */
  12. class Time {
  13. //put your code here
  14. /**
  15. * 获取服务端的本地时间戳
  16. * 客户端时间同步,这个是后期加密算法的关键
  17. * @param type $offset 时间偏移:用于某些服务端有必要出现时间偏差的情况
  18. * @return type
  19. */
  20. static function now($offset=0){
  21. return time() + $offset;
  22. }
  23. /**
  24. * 获取当前小时数
  25. * @param type $time
  26. * @return type
  27. */
  28. static function hours($time=-1){
  29. if($time<0){
  30. $time = TimeUtil::tsCurrent();
  31. }
  32. return CommUtil::floatToInt($time/3600); // 东八区前提8小时时差
  33. }
  34. /**
  35. * 获取当前天数
  36. * 检测玩家连续登录及隔天刷新操作用
  37. * @param type $time 当前时间戳
  38. * @return type
  39. */
  40. static function days($time=-1){
  41. if($time<0){
  42. $time = TimeUtil::tsCurrent();
  43. }
  44. return CommUtil::floatToInt(($time + 28800)/86400); // 东八区前提8小时时差
  45. }
  46. /**
  47. * 获取当前的周目数
  48. * @param type $time
  49. * @return type
  50. */
  51. static function weeks($time=-1){
  52. return CommUtil::floatToInt((TimeUtil::tsDay($time)+3)/7);
  53. }
  54. /**
  55. * 获取当前的日期时间
  56. * @return \Date
  57. */
  58. static function date($time=0){
  59. return new Date($time);
  60. }
  61. }