PHP Time-Date Conversion _php Tutorial

Source: Internet
Author: User
This article introduces a time-date conversion custom function in PHP that can be used to convert events representing seconds to years, months, days, hours, and other time formats.
The code is as follows Copy Code

function Sec2time ($time) {
if (Is_numeric ($time)) {
$value = Array (
"Years" = 0, "days" = 0, "hours" = 0,
"Minutes" = 0, "Seconds" and "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;
}
}

http://www.bkjia.com/PHPjc/631653.html www.bkjia.com true http://www.bkjia.com/PHPjc/631653.html techarticle This article introduces a time-date conversion custom function in PHP that can be used to convert events representing seconds to years, months, days, hours, and other time formats. The code below copies the code F ...

  • 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.