PHP Date and Time Functions
1. Time Zone settings
Method 1: set date. timezone = Asia/Hong_Kong of php. ini so that the default system time is East 8.
Method 2: Use the date_default_timezone_set () function to set the time zone to date_default_timezone_set ("Asia/Hong_Kong ")
2. Get the current Timestamp
Use the time () function to directly return the current time and date. The timestamp indicates the number of seconds from 00:00:00 on January 1, January 1, 1970 to the program running time.
3. Get the current date and time
Use the date () function to return the current date. Date () has many parameters. For example, if "d" is used, the date from 01 to 31 of the current month is returned.
4. Resolve the date and time to the Unix Timestamp
You can use the maketime () function to generate a Unix timestamp.
The following is an example:
Date_default_timezone_set ("Asia/Hong_Kong ");
$ Timefuture = mktime );
$ Timenow = time ();
$ Timecount = $ timefuture-$ timenow;
$ Day = round ($ timecount/86400 );
Echo date ("Current Time: Y, m, d, [l] H: I minute s seconds", $ timenow )."
";
Echo "is still". $ day. "days from January 1, January 1, 2016. "."
";
?>
The running result is: