funct Ion DateDiff ($date 1, $date 2, $unit = "") {//Time comparison function, return two dates in seconds, minutes, hours or days
switch ($unit) {
C ASE ' s ':
$dividend = 1;
break;
case ' I ':
Time Functions: strftime format local time/date strptime & mdash according to region settings; parse the date/time setlocale function generated by strftime () to set region information (Region information) date_default_timezone_set if the result of
Returns the timestamp of all months in a time period
function Monthlist ($start, $end) {
if (!is_numeric ($start) | |! Is_numeric ($end) | | ($end
$start =date (' y-m ', $start);
$end =date (' y-m ', $end);
Convert to
1. Calculate the data issue between the current time and the same time period of yesterday
This problem requires you to know the current time and the time after the current time minus 24
Method 1: Use time () and date ()
For example:
$ Time = time ()
Checkdate: Verify that the date is correct.
Date: format the server time.
Strftime: format the server time locally.
Getdate: Get the time and date information.
Gettimeofday: Get the current time.
Gmdate: Get the current time difference from
In php, we want to add or subtract time and date. We can use two functions: mktime and strtotime. Next I will introduce you to their usage.
Mktime Function
The mktime () function returns the Unix timestamp of a date.
The parameter always represents
Available values in mainland China: Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (in the order of Chongqing, Shanghai, and Urumqi)Available in Hong Kong and Taiwan regions: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (in the order of Macao, Hong Kong, and
// Calculate the number of days from January 1, January 1, a.m., $ mm, and $ dd. function datelocal ($ yyyy, $ mm, $ dd) { $ monthdays = array (, 28, 31 ); // The number of days of a month in a non-leap year // determines whether the value is a
PHP inside About Time function has date,time,strtotime,gmdate, inside as long as the time string related to the basic receive time zone effect, so timestamp is the only stable time record, because the standards are unified.This reminds of the
Get the start and end of the time stamp of the week (This day)Time stamp of the week Monday$monday = mktime (0, 0, 0, date ("M", Strtotime ("last Monday")), date ("D", Strtotime ("Last Monday"), Date ("Y", Strtotime ("l AST Monday ")));Time stamp of
To do time data conversion to timestamp we use the PHP tutorial with functions, the strtotime () function resolves the date-time description of any English text to a Unix timestamp
Format one Fri Aug 05 12:19:04 +0800 2011
Strtotime ("Fri Aug 05
PHP scripts are executed in three states:
0-normal (Normal)
1-aborted (Abnormal exit)
2-timeout (Timeout)
The normal state is normally executed, the aborted state is the client terminal link, and the timeout status is PHP
All functions in PHP are in the Unix era, starting January 1, 1970.
The date is the number of seconds to start at this time.
When a function call is counted as a number of seconds from this time, it is treated as a (timestamp) timestamp.
local
Commonly used time functions:
1.time (); The total number of seconds from 1970/1/1 00:00:00 to today
2.mktime (); Set time
3.date (); More information on getting time
represents a String
Description
Example
Output
Checkdate:
Verify the correctness of the date.
Date:
Format the time of the server.
Strftime:
The time of the server is formatted locally.
GETDATE:
Get time and date information.
format character
Description
return Value Example
Day
---
---
D
The first day of the month with a leading zero of 2 digits
01 to 31
J
Days of the month, no leading zeros
1 to 3
Date ("Y-m-d", Time ()) gets a string of times in a particular format. Time () is a timestamp value, or it can be omitted, the default current time. You can also fill in the value.All functions in PHP are in the Unix era, starting January 1, 1970.
Here are some of the time functions in PHP:(1) DateUsage: Date (format, [time]);If there is no time parameter, the current time is used. The format is a string, where the following characters have special meanings:U is replaced by the number of
Date operations are common. The following is a simple feature. The main requirement is to differentiate between the time structures commonly used in PHP. Take a look at the following piece of code, which involves most of the time manipulation
Ec (2); setlocale () mktime () getdate obtains the time and date information. Syntax: arraygetdate (inttimestamp); Return Value: Array Function Type: time and date content description returned array elements include the following items: & quot;
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.