Time format conversion problems

Source: Internet
Author: User
Time format conversion question & nbsp; 22:26:56 how to convert the above time format to 3 seconds ago or 3 days ago this Format Display Share to: more ------ time format conversion question
22:26:56
How to convert the preceding time format to 3 seconds ago or 3 days ago

Share: More


------ Solution --------------------
Http://www.baidu.com? Wd = Smarty % E6 % A8 % A1 % E6 % 9D % BF % E5 % 87% BD % E6 % 95% B0 & ie = UTF-8
------ Solution --------------------
Reference:
Quote: reference:

Http://www.baidu.com? Wd = Smarty % E6 % A8 % A1 % E6 % 9D % BF % E5 % 87% BD % E6 % 95% B0 & ie = UTF-8

I still don't quite understand it. can you give me more details? For example, how do I modify the following code to a Smarty template function?
Function sgmdate ($ dateformat, $ format = 0) {$ result = ''; if ($ format) {$ time = time ()-$ dateformat; if ($ time> 24*3600) {$ result = date ('Y-m-D', $ dateformat);} elseif ($ time> 3600) {$ result = intval ($ time/3600 ). 'hour before ';} elseif ($ time> 60) {$ result = intval ($ time/60 ). 'minute ago ';} elseif ($ time> 0) {$ result = $ time. 'seconds ago ';} else {$ result =' ';} else {$ result = date ('Y-m-D', $ dateformat );} return $ result ;}

The template source code is as follows:





Smarty template engine
Then you can find it in your php file.
$ Tpl-> assign ("home", $ home );
Before that, add the following sentence and you will be OK:
$ Home ['regtime'] = sgmdate ($ home ['regtime'], 1 );

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.