Several steps for obtaining time in php (collection)

Source: Internet
Author: User
Several methods for getting time in php (collection) 1. jddayofweek (cal_to_jd (CAL_GREGORIAN, date ('M'), date ('D '), date ('Y'); this function returns the day of the Week 2, array ('mon' = & gt; 'Monday ',......); then you can directly subscripts to query 3. several methods for getting time in the root php (collection)
1. jddayofweek (cal_to_jd (CAL_GREGORIAN, date ('M'), date ('D'), date ('Y'); this function returns the number of days in the week
2. array ('mon '=> 'Monday',...); then directly subscript query
3. get the week-based custom functions
 '; Echo' today is: '. getWeekName (time (), 'week'); echo'
'; Echo '2017-12-12 is:'. getWeekName (strtotime ('2017-12-12 '), 'week');?>

4. get the user-defined functions for the effects such as a few hours ago posted in a similar article
 'Year', 'month' => 'month', 'week' => 'week', 'day' => 'day ', 'hour '=> 'hour', 'mine' => 'Minute ', 'second' => 'second'); foreach ($ unitArr as $ cn => $ u) {if ($ u> 0) {$ elapse = $ u. $ cn; break ;}}return $ elapse ;}$ past = 2052345678; // release date $ now = time (); // Current date $ diff = $ now-$ past; // difference echo 'published on '. time2Units ($ diff ). 'pre';?>

In other words, I think it is better:
Function time_tran ($ the_time) {$ now_time = date ("Y-m-d H: I: s", time () + 8*60*60 ); $ now_time = strtotime ($ now_time); $ show_time = strtotime ($ the_time); $ dur = $ now_time-$ show_time; if ($ dur <0) {return $ the_time ;} else {if ($ dur <60) {return $ dur. 'seconds ago ';} else {if ($ dur <3600) {return floor ($ dur/60 ). 'minute ago ';} else {if ($ dur <86400) {return floor ($ dur/3600 ). 'hour before ';} else {if ($ dur <259200) {// return floor ($ dur/86400) within 3 days ). 'Day' ;}else {return $ the_time ;}}}}}}

5. calculate the time difference based on the difference
Function getTime ($ val) {if ($ val> 0) {$ nTime ['nday'] = (int) ($ val/(3600*24 )); $ nTime ['nhour'] = (int) ($ val % (3600*24)/3600); $ nTime ['nmin'] = (int) ($ val % (3600*24) % 3600/60); $ nTime ['nss'] = (int) ($ val % (3600*24) % 3600% 60 );} return $ nTime;} function getStrTime ($ val) {$ aTime = getTime ($ val); $ dtoc = array ('nday' => 'day ', 'nhour' => 'hour ', 'nmin' => 'Minute', 'nss' => 'second '); if ($ aTime) {foreach ($ aTime as $ k => $ v) {if ($ v) {$ cTime. = $ v. $ dtoc [$ k] ;}}else {$ cTime = 'stopped;} return $ cTime ;}

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.