How PHP Gets the timestamp and date of the month and day

Source: Internet
Author: User
PHP get Timestamp is implemented by the PHP time () function, the PHP get date is implemented by the PHP data () function, they are specifically how to implement, the following gives a concrete example.

Setting the time zone

Date_default_timezone_set ("Asia/shanghai"); Date_default_timezone_set (' PRC ');//The two methods have the same effect

Time stamp to date, can be used date(‘Y-m-s h:i:s’, 具体时间戳来实现)
Date conversion timestamp, with strtotime("date()") .

Time stamp format

Gets the start timestamp and end timestamp for today $beginToday =mktime (0,0,0,date (' m '), date (' d '), date (' Y '));  $endToday =mktime (0,0,0,date (' m '), date (' d ') +1,date (' Y '))-1;  Gets the start timestamp and end timestamp of yesterday $beginYesterday =mktime (0,0,0,date (' m '), date (' d ') -1,date (' Y '));  $endYesterday =mktime (0,0,0,date (' m '), date (' d '), date (' Y '))-1;  Gets the starting timestamp and end timestamp of the week $beginThisweek = Mktime (0,0,0,date (' m '), date (' d ')-date (' W ') +1,date (' Y '));  $endThisweek =time ();  Get last week start timestamp and end timestamp $beginLastweek =mktime (0,0,0,date (' m '), date (' d ')-date (' W ') +1-7,date (' Y '));  $endLastweek =mktime (23,59,59,date (' m '), date (' d ')-date (' W ') +7-7,date (' Y '));  Gets the start timestamp and end timestamp of the month $beginThismonth =mktime (0,0,0,date (' m '), 1,date (' Y '));   $endThismonth =mktime (23,59,59,date (' m '), date (' t '), date (' Y '));  Last month's start time: $begin _time = strtotime (Date (' y-m-01 00:00:00 ', Strtotime ('-1 month ')); $end _time = strtotime (Date ("Y-m-d 23:59:59", Strtotime (-date (' d ').  Day ')); $begin _year = strtotime (Date ("Y", Time ()). " -1 "." -1 "); Starting this year $end _year = strtotime (Date ("Y", Time ()). " -12 "." -31 "); End of year//Present time toThe time stamp of the next morning difference $time = (strtotime (' y-m-d ') +3600*24)-Times (); 

Date format

    Echo ' <br> last week start time:<br> ';    echo Date ("Y-m-d h:i:s", mktime (0, 0, 0,date ("M"), Date ("D")-date ("W") +1-7,date ("Y")), "\ n";    echo Date ("Y-m-d h:i:s", Mktime (23,59,59,date ("M"), Date ("D")-date ("W") +7-7,date ("Y")), "\ n";    Echo ' <br> this week start time:<br> ';    echo Date ("Y-m-d h:i:s", mktime (0, 0, 0,date ("M"), Date ("D")-date ("W") +1,date ("Y")), "\ n";    echo Date ("Y-m-d h:i:s", Mktime (23,59,59,date ("M"), Date ("D")-date ("W") +7,date ("Y")), "\ n";    Echo ' <br> last month start time:<br> ';    echo Date ("Y-m-d h:i:s", mktime (0, 0, 0,date ("M") -1,1,date ("Y")), "\ n";    echo Date ("Y-m-d h:i:s", Mktime (23,59,59,date ("M"), 0,date ("Y")), "\ n";    Echo ' <br> month start time:<br> ';    echo Date ("Y-m-d h:i:s", mktime (0, 0, 0,date ("M"), 1,date ("Y")), "\ n";    echo Date ("Y-m-d h:i:s", Mktime (23,59,59,date ("M"), Date ("T"), Date ("Y")), "\ n";    This year begins with    echo date (' y-01-01 ');     End Date     (' y-12-31 ');

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.