Date.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /*
  3. * To change this template, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. /**
  7. * Description of DateTimeEx
  8. *
  9. * @author jgao
  10. */
  11. class Date {
  12. //put your code here
  13. /**
  14. * 年
  15. * @var type
  16. */
  17. public $year;
  18. /**
  19. * 月
  20. * @var type
  21. */
  22. public $month;
  23. /**
  24. * 日
  25. * @var type
  26. */
  27. public $day;
  28. /**
  29. * 星期
  30. * @var type
  31. */
  32. public $dayofweek;
  33. /**
  34. * 时
  35. * @var type
  36. */
  37. public $hours;
  38. /**
  39. * 分
  40. * @var type
  41. */
  42. public $minutes;
  43. /**
  44. * 秒
  45. * @var type
  46. */
  47. public $seconds;
  48. /**
  49. * 时间戳
  50. * @var type
  51. */
  52. public $time;
  53. function __construct($time=0){
  54. if($time==0){
  55. $this->time = time();
  56. }else{
  57. $this->time = $time;
  58. }
  59. $date_reg = date("Y:m:d:H:i:s:N",$this->time);
  60. $date_info = explode(":",$date_reg);
  61. $i = 0;
  62. $this->year = intval($date_info[$i++]);
  63. $this->month = intval($date_info[$i++]);
  64. $this->day = intval($date_info[$i++]);
  65. $this->hours = intval($date_info[$i++]);
  66. $this->minutes = intval($date_info[$i++]);
  67. $this->seconds = intval($date_info[$i++]);
  68. $this->dayofweek = intval($date_info[$i++]);
  69. }
  70. function toString(){
  71. return date("Y-m-d H:i:s", $this->time);
  72. }
  73. }
  74. ?>