PHP time and date functions _ PHP Tutorial

Source: Internet
Author: User
Tags month name
PHP time and date functions. A detailed explanation of PHP time and date functions shows that the diversity and functionality of php functions are similar. the same application can be implemented using multiple functions, which may be a disadvantage of open source; explanation of PHP time and date functions

The diversity and functionality of php functions are really similar. the same application can be implemented using multiple functions, which is probably a drawback of Open Source. through the system learning of PHP time functions, I fully understand the concept of timestamp and time zone (this is really important). If you need it, you can refer to it.

All functions in PHP are in the UNIX era, that is, since January 1, 1970.

The date is the number of seconds from this time.

When a function is called in seconds, it is treated as a timestamp.

Local time functions

1. string date (string format, inieger timestamp)

This function returns a time string controlled by string format.

For example:

?

1

2

3

4

Print (date ("Y, m, d"); // output current, year, month, and day.

Print (date ("Y, m, d,", 60*60*24*365*10); // output for April 1, January 1, 1980.

?>

Maybe you will ask, why is there no timestamp? If the timestamp is null or is not written, the current timestamp is used.

The control operator of the year: Y --- four-digit year y --- two-digit year

Indicates the control operator of the month: m --- from month F --- English month name M --- abbreviated month name

Control operator for day: d --- date j in the month with 0 in front -- date without 0 in front

Indicates the control letter of the week: l -- English week D -- abbreviation of the week

The hour controller: h -- hour from 1 to 12 H --- hour from 0 to 23

Represents the Upper afternoon controller a --- am or pm A---AM or PM

Indicates the minute controller: I --- value 00-59

The number of days in a year: z -- the number of days in a year

2. array getdate (integer timestamp)

This function returns a matrix.

For example:

?

1

2

3

4

5

6

$ Current_date = getdate ();

Print ($ current_date ("hours "));

Print ($ current_date ("minutes ");

Print ($ current_date ("seconds ");

?>

Note:

Element description

Hour in the 24-hour format

Date in mday month

Minutes

Month in the form of mon

Full name of month

Seconds

The number of weeks in the format of 0 to 6 for wday

Weekday

Year

0 timestamp is the number of seconds from January 1, January 1, 1970 to the present.

A date in the digit format of a year in yday

3. boolean checkdate (integer month, integer day, integer year)

This function checks whether the date is valid. for example:

?

1

2

3

4

If (checkdate (2, 29, 1980 ))

Print ("date is valid! N ");

?>

4. integer time ()

This function obtains the current timestamp. for example:

?

1

2

3

Print (time (); // output a large integer string

?>

5. integer mktime (integer hour, integer minutes, integer seconds, integer month, integer day, integer year)

This function returns the timestamp of the given date, that is, the number of seconds from January 1, January 1, 1970 to the present.

If a parameter is out of the range, this function can also be interpreted, for example, 13 months is the second year of January.

For example:

?

1

2

3

4

5

6

$ Currenthour = date ("H ");

Print ("50 hours later :");

Print (date ("h: I A l F dS, Y", mktime ($ currenthour + 50 )));

Print ("
N ");

?>

6. string microtime ()

This function returns a string, in milliseconds of the current time + spaces + seconds starting from January 1, 1970

?

1

2

3

4

5

6

Print ("start: microtime ()
N ");

For ($ index = 0; $ index <1000; $ index ++)

Print ("good! ");

Print ("stop: microtime ()
N ");

?>

Also, standard time functions of various Linwei governance

The above is all the content of this article. I hope you will like it.

Note <>: For more exciting tutorials, please pay attention to the help house programming

The diversity and functionality of the same php functions are really a major feature. the same application can be implemented using multiple functions, which is probably a drawback of open source...

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.