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 ');