Php instance sharing: display the website running time

Source: Internet
Author: User

Let's talk about the code.

Copy codeThe Code is as follows:
<? Php
// Set the time zone
Date_default_timezone_set ('Asia/Shanghai ');
/**
* Second to second, in the format of year month day hour minute second
*
* @ Author wangyupeng129@126.com
* @ Param int $ time
* @ Return array | boolean
*/
Function Sec2Time ($ time ){
If (is_numeric ($ time )){
$ Value = array (
"Years" => 0, "days" => 0, "hours" => 0,
"Minutes" => 0, "seconds" => 0,
);
If ($ time> = 31556926 ){
$ Value ["years"] = floor ($ time/31556926 );
$ Time = ($ time % 31556926 );
}
If ($ time> = 86400 ){
$ Value ["days"] = floor ($ time/86400 );
$ Time = ($ time % 86400 );
}
If ($ time> = 3600 ){
$ Value ["hours"] = floor ($ time/3600 );
$ Time = ($ time % 3600 );
}
If ($ time> = 60 ){
$ Value ["minutes"] = floor ($ time/60 );
$ Time = ($ time % 60 );
}
$ Value ["seconds"] = floor ($ time );
Return (array) $ value;
} Else {
Return (bool) FALSE;
}
}

// Time when this site was created
$ Site_create_time = strtotime ('2017-05-22 00:00:00 ');
$ Time = time ()-$ site_create_time;
$ Uptime = Sec2Time ($ time );
?>

Run on this site: <span style = "color: red;"> <? Php echo $ uptime ['ears'];?> Year <? Php echo $ uptime ['days'];?> Day <? Php echo $ uptime ['hours'];?> Hour <? Php echo $ uptime ['minutes '];?> Score <? Php echo $ uptime ['seconds'];?> Seconds </span>

Related Article

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.