search
Homephp教程PHP开发Example of converting php time to seconds

Converting PHP time to seconds is very simple. We use the strtotime function. Let’s introduce it to you here. I hope the article can help you.

Convert the time string in the format of HH:MM:SS into seconds, you can use the date_parse function to parse specific time information.

<?php 
  $time = &#39;21:30:10&#39;; 
  $parsed = date_parse($time); 
  $seconds = $parsed[&#39;hour&#39;] * 3600 + $parsed[&#39;minute&#39;] * 60 + $parsed[&#39;second&#39;]; 
  echo $seconds;
?>

More detailed examples, how many days/hours/minutes to convert

function get_stay_time($timestamp, $is_hour = 1, $is_minutes = 1) 
{ 
    $CI =& get_instance(); 
    if(emptyempty($timestamp) || $timestamp <= 60) { 
        return false; 
    } 
    $time = time(); 
    $remain_time = $time - $timestamp; 
    $day = floor($remain_time / (3600*24)); 
    $day = $day > 0 ? $day.&#39;天&#39; : &#39;&#39;; 
    $hour = floor(($remain_time % (3600*24)) / 3600); 
    $hour = $hour > 0 ? $hour.&#39;小时&#39; : &#39;&#39;; 
    if($is_hour && $is_minutes) { 
        $minutes = floor((($remain_time % (3600*24)) % 3600) / 60); 
        $minutes = $minutes > 0 ? $minutes.&#39;分&#39; : &#39;&#39;; 
        return $day.$hour.$minutes; 
    } 
    if($hour) { 
        return $day.$hour; 
    } 
    return $day; 
}

The above is the content of the example of converting PHP time into seconds, more For related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)