Php date processing function (calculate time difference, convert timestamp date ). The conversion timestamp of the php Tutorial is a commonly used date format and calculation Time difference: the default return type is minute functiontrans_time ($ timestamp) {if ($ timestamp1) echo invalid unix timestamp; e php Tutorial converts the timestamp to a commonly used date format and computing Time difference: the default return type is "minute"
Function trans_time ($ timestamp ){
If ($ timestamp <1) echo 'invalid unix timestamp ';
Else return date ("y-m-d h: I: s", $ timestamp );
}
// Obtain the ip address
Function get_ip (){
If ($ _ server ["http_x_forwarded_for"])
$ Ip = $ _ server ["http_x_forwarded_for"];
Else if ($ _ server ["http_client_ip"])
$ Ip = $ _ server ["http_client_ip"];
Else if ($ _ server ["remote_addr"])
$ Ip = $ _ server ["remote_addr"];
Else if (getenv ("http_x_forwarded_for "))
$ Ip = getenv ("http_x_forwarded_for ");
Else if (getenv ("http_client_ip "))
$ Ip = getenv ("http_client_ip ");
Else if (getenv ("remote_addr "))
$ Ip = getenv ("remote_addr ");
Else
$ Ip = "unknown ";
Return $ ip;
}
// Calculation Time difference: the default return type is minute"
// $ Old_time can only be a timestamp. $ return_type indicates that h is an hour, and s is a second.
Function timelag ($ old_time, $ return_type ='m '){
If ($ old_time <1 ){
Echo 'invalid unix timestamp ';
} Else {
Switch ($ return_type ){
Case 'H ':
$ Type = 3600; break;
Case'm ':
$ Type = 60; break;
Case's ':
$ Type = 1; break;
Case '':
$ Type = 60; break;
}
$ Dif = round (time ()-$ old_time)/$ type );
Return $ dif;
}
}
The time difference between values and common date formats: the default return type is minute function trans_time ($ timestamp) {if ($ timestamp 1) echo 'invalid unix timest '; e...