date_class.php
1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* Tiny - A PHP Framework For Web Artisans
* @author Tiny <tinylofty@gmail.com>
* @copyright Copyright(c) 2010-2014 http://www.tinyrise.com All rights reserved
* @version 1.0
*/
/**
* 时间封装类
*
* @author Tiny
* @class Date
*/
class Date
{
private $time;
/**
* 初始化时区、时间设定
*
* @access public
* @param string $time
* @param string $timezone
* @return mixed
*/
public function __construct($time = "now", $timezone = 'Asia/Shanghai')
{
date_default_timezone_set($timezone);
$this->time = time();
if($time != 'now')$this->time=strtotime($time);
}
/**
* 时间格式化
*
* @access public
* @param mixed $format
* @return mixed
*/
public function format($format)
{
return date($format,$this->time);
}
/**
* 时间相加
*
* @access public
* @param mixed $time
* @return mixed
*/
public function add($time)
{
if(is_int($time)) $this->time + $time;
else return $this->time+strtotime($time);
}
/**
* 时间差
*
* @access public
* @param mixed $time
* @return mixed
*/
public function diff($time)
{
if(is_int($time)) return $this->time - $time;
return $this->time-strtotime($time);
}
}
?>