PHP Time and date

Source: Internet
Author: User
Tags echo date set time time and date

 
   
  
  1. echo date(‘Y-m-d H:i:s‘);

date_default_timezone_set (' PRC '); Set time zone
echo Date_default_timezone_get (); Gets the time zone information set by the server
Create function return timestamp mktime (1,2,22,1,5,2015)
 
   
  
  1. echo mktime(1,2,22,1,5,2015).‘<br>‘;
  2. echo date(‘Y-m-d H:i:s‘,1420390942);

time () Gets the timestamp of the current system,
 
   
  
  1. echo time();
  2. echo date(‘Y-m-d H:i:s‘,1431697515);

strtotime (' 1983-1-1 ')Timestamp of converting a date string to a number
  
 
    1. $time=strtotime(‘1983-1-1‘);
    2. echo $time.‘<br>‘;
    3. echo date(‘Y年m月d日‘,410198400);

trtotime (' +2 Day ') returns the timestamp after 2 days
 
   
  
  1. echo strtotime(‘+2 day‘).‘<br>‘;
  2. echo date(‘Y-m-d H:i:s‘,1431871146);

Statistical message Time
  
 
  1. $time="2015-5-15 22:17:1";
  2. $t=strtotime($time);//输出$time的时间戳
  3. $now=time(); //输出现在时间的时间戳
  4. $rr=floor(($now-$t)/86400);//floor 表示取整数 $rr 表示现在距离留言时间的时间差为多少
  5. $hh=floor(($now-$t)/3600);
  6. $mm=floor(($now-$t)/60);
  7. $ss=floor($now-$t);
  8. if($rr>=30){
  9. echo "留言时间为:$time";
  10. }else if($rr>=1){
  11. echo $rr.‘天前‘;
  12. }else if($hh>=1){
  13. echo $hh.‘小时前‘;
  14. }else if($mm>=1){
  15. echo $mm.‘分钟前‘;
  16. }else{
  17. echo $ss.‘秒前‘;
  18. }

Statistics for member registration information within 7 days select COUNT (*) from member where regtime between Strtotime ('-7 days ') and time ();





From for notes (Wiz)

PHP Time and date

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.