Time format conversion

Source: Internet
Author: User
Tags echo date
Time format conversion question 22:26:56
How to convert the preceding time format to 3 seconds ago or 3 days ago


Reply to discussion (solution)

$ Time = '2017-11-01 22:26:56 '; echo date ('Y-m-d H: I: S', strtotime ($ time)-3 ); // echo 3 seconds ago"
"; Echo date ('Y-m-d H: I: S', strtotime ($ time)-3*24*60*60); // 3 days ago

function time_since($since) {    $chunks = array(        array(60 * 60 * 24 * 365 , 'year'),        array(60 * 60 * 24 * 30 , 'month'),        array(60 * 60 * 24 * 7, 'week'),        array(60 * 60 * 24 , 'day'),        array(60 * 60 , 'hour'),        array(60 , 'minute'),        array(1 , 'second')    );    for ($i = 0, $j = count($chunks); $i < $j; $i++) {        $seconds = $chunks[$i][0];        $name = $chunks[$i][1];        if (($count = floor($since / $seconds)) != 0) {            break;        }    }    $print = ($count == 1) ? '1 '.$name : "$count {$name}s";    return $print;}

The code is as follows:


The time format displayed on the webpage is: 1382972373. how to convert the time format to three seconds ago or three days ago

This is more convenient and you don't need to change it:

$ Time = '000000'; echo date ('Y-m-d H: I: S', $ time-3); // echo 3 seconds ago"
"; Echo date ('Y-m-d H: I: S', $ time-3*24*60*60); // 3 days ago

If you want to display the timestamp in the result, you do not need to convert date:
$ Time = '000000'; echo $ time-3; // echo 3 seconds ago"
"; Echo $ time-3*24*60*60; // 3 days ago

[/Code]

The code is as follows:


The time format displayed on the webpage is: 1382972373. how to convert the time format to three seconds ago or three days ago

What do you mean is how many minutes ago weibo was published? You can use the function that I sent.

Yes, just like how many minutes ago the weibo app was released, how can it be called?

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.