php tutorial conversion timestamp for the common date format and calculation of time difference: the default return type is "minutes" function trans_time ($ timestamp) { if ($ timestamp <1) echo 'invalid unix timestamp'; else return date ("ymd h: i: s", $ timestamp); }
// Get ip 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; }
// calculate the time difference: the default return type is "minutes" // $ old_time can only be a timestamp, $ return_type is h is hour, s is 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 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.