Php date processing function (calculation time difference, conversion timestamp date) _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.