Rumah > php教程 > php手册 > PHP版实现友好的时间显示方式(例如:2小时前),php显示方式

PHP版实现友好的时间显示方式(例如:2小时前),php显示方式

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Lepaskan: 2016-06-13 09:21:01
asal
1066 orang telah melayarinya

PHP版实现友好的时间显示方式(例如:2小时前),php显示方式

完整php类,通常我会配合smary使用,快捷使用 (plugins/function.rdate.php),更多php技术开发就去php教程网,http://php.662p.com

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

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

<?PHP

/*

* Data time functions.

  // * 模块

*/

defined('TSKY') || die('Permission Denied!');

 

function fmtMonth($month){

    return date('F, Y',day2time($month.'01'));

}

 

//

function fmt_month($ts) {

    return strftime("%b,%Y",$ts);

}

 

// 03:02

function shartTime($ts) {

    return strftime("%H:%M",$ts);

}

// 03:02:01

function longTime($ts) {

    return strftime("%T",$ts);

}

//4月18日

function shortDate($ts) {

    return date("n月d日",$ts);

}

//2006年4月18日

function longDate($ts) {

    return date("Y年n月d日",$ts);

}

 

function dateTime($ts) {

    return date("Y年n月d日 H:i:s",$ts);

}

function fullDateTime($ts) {

    return date("Y年n月d日 ",$ts).week($ts);

}

function week($ts) {

    global $lang;

    return  $lang['weekDay'][date('w',$ts)];

}

 

function relatively_date($date) {

    if (!preg_match('/^\d+$/', $date)) $date = strtotime(trim($date));

    $sec = time() - $date;

    switch(true){

        case $sec < 3600:

            return round($sec/60). ' 分钟前';

        case $sec < 86400:

            return round($sec/3600). ' 小时前';

        case $sec < (86400 * 7):

            return round($sec/86400). ' 天前';//days ago

        case $sec < (86400 * 7 * 4):

            return round($sec/(86400*7)). ' 周前'; //weeks ago

        default:

            return longDate($date);

    }

}

 

function nextMonth($month/*200512->200601*/){

    return date('Ym',strtotime('+1 month',strtotime($month.'01')));

}

function prevMonth($month/*200512->200511*/){

    return date('Ym',strtotime('-1 month',strtotime($month.'01')));

}

function prevDay($day/*20050826*/){

    $day = substr($day,0,8);

    return date('Ymd',strtotime('-1 day',strtotime($day)));

}

 

function nextDay($day/*20050826*/){

    $day = substr($day,0,8);

    return date('Ymd',strtotime('+1 day',strtotime($day)));

}

function nextExistsDay($day/*20050109*/){

    $day = nextDay($day);

    while(!hasTopic($day) && $day < TODAY){

        $day = nextDay($day);

    }

    return hasTopic($day) ? $day : false;

}

function prevExistsDay($day/*20050109*/){

    global $cfg;

    $day = prevDay($day);

    while(!hasTopic($day) && (int)$day > $cfg->origDate){

        $day = prevDay($day);

    }

    return hasTopic($day) ? $day : false;

}

 

 

function prev_day($day){$day = substr($day,0,8);return date('Ymd',strtotime('-1 day',strtotime($day)));}

function long_date($ts){return date("Y年n月d日",$ts);}

function day2time($day){return @strtotime($day);}

 

 

 

 

 

/*

echo "<pre class="brush:php;toolbar:false">";

echo strftime("a%a\n"); //  a  星期二            

echo strftime("A%A\n"); //  A  星期二            

echo strftime("b%b\n"); //  b  四月              

echo strftime("B%B\n"); //  B  四月              

echo strftime("c%c\n"); //  c  2006-4-18 3:48:11 

echo strftime("C%C\n"); //  C                    

echo strftime("d%d\n"); //  d  18                

echo strftime("D%D\n"); //  D                    

echo strftime("e%e\n"); //  e                    

echo strftime("g%g\n"); //  g                    

echo strftime("G%G\n"); //  G                    

echo strftime("h%h\n"); //  h                    

echo strftime("H%H\n"); //  H  03                

echo strftime("I%I\n"); //  I  03                

echo strftime("j%j\n"); //  j  108               

echo strftime("m%m\n"); //  m  04                

echo strftime("M%M\n"); //  M  48                

echo strftime("n%n\n"); //  n                    

echo strftime("p%p\n"); //  p  上午              

echo strftime("r%r\n"); //  r                    

echo strftime("R%R\n"); //  R                    

echo strftime("S%S\n"); //  S  11                

echo strftime("t%t\n"); //  t                    

echo strftime("T%T\n"); //  T                    

echo strftime("u%u\n"); //  u                    

echo strftime("U%U\n"); //  U  16                

echo strftime("V%V\n"); //  V                    

echo strftime("W%W\n"); //  W  16                

echo strftime("w%w\n"); //  w  2                 

echo strftime("x%x\n"); //  x  2006-4-18         

echo strftime("X%X\n"); //  X  3:48:11           

echo strftime("y%y\n"); //  y  06                

echo strftime("Y%Y\n"); //  Y  2006              

echo strftime("Z%Z\n"); //  Z  中国标准时间      

echo strftime("%%%\n"); //  %                    

*/

Salin selepas log masuk

  详细说明:http://php.662p.com/thread-571-1-1.html

Label berkaitan:
php
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Cadangan popular
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan