PHP time and Date function detailed _php tutorial

Source: Internet
Author: User
Tags month name time and date

PHP time and date functions in a detailed


PHP function of the diversification and functional similarity is really a big feature, the same application can be implemented with a variety of functions, which is probably a disadvantage of open source, through the PHP time function of the system learning, fully understand the time stamp and time zone concept (this is really important), the need for small partners to refer to.

All functions in PHP are in the Unix era, starting January 1, 1970.

The date is the number of seconds from this time onwards.

When a function call is counted as the number of seconds from this time, it is treated as a (timestamp) timestamp.

local time function

1. String date (string Format,inieger timestamp)

The function returns a string representing the time, which is controlled by the string format.

Such as:

?

1

2

3

4

Print (Date ("Y year M D Day");//output current, month date.

Print (Date ("Y year M month D Day", 60*60*24*365*10);//Output January 1, 1980.

?>

You might ask, how come there's no timestamp? If the timestamp is empty, or does not write, it means to use the current time moment timestamp.

The control that represents the year: Y---Four-bit year y---two-bit year

The controller that represents the month: M---month name from the month of 1-12 F---English month name m---abbreviated

The control that represents the day number: D---preceded by 0 of the month in the date j--before the day number 0

The week's control: l--English week d--abbreviated week

The control for the hour: h--from 1-12 hours h---from 0 to 23 hours

Represents the last afternoon's control of a---am or pm a---am or pm

The control that represents the minute: I---value 00-59

Indicates the number of days of the Year: z--the number of days of the year

2. Array getdate (integer timestamp)

The function returns a matrix.

Such as:

?

1

2

3

4

5

6

$current _date=getdate ();

Print ($current _date ("hours"));

Print ($current _date ("minutes");

Print ($current _date ("seconds");

?>

Description

Element description

Hours hours in 24-hour format

Mday date in month

Minutes min

Mon digital form of month

Month Full Name

Seconds number of seconds

Wday number of weeks from 0 to 6

Weekday name of the week

Year years

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

Yday date of the year in digital form

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

The function checks if the date is legal. For example:

?

1

2

3

4

if (Checkdate (2,29,1980))

Print ("date valid!n");

?>

4. Integer time ()

The function obtains the current timestamp. such as:

?

1

2

3

Print (Time ());//output a large string of integers

?>

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

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

If a parameter goes out of scope, the function can also interpret it, as 1 March is the January of the second year.

Such as:

?

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 ()

The function returns a string that is the number of milliseconds from the current time + space + seconds since 1970

?

1

2

3

4

5

6

Print ("Start:microtime ()
n ");

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

Print ("good!");

Print ("Stop:microtime ()
n ");

?>

Also, each Linwei standard Time function

The above mentioned is the whole content of this article, I hope you can like.

Note < > : More Exciting tutorials please focus on helping the home program

http://www.bkjia.com/PHPjc/996754.html www.bkjia.com true http://www.bkjia.com/PHPjc/996754.html techarticle php time and date function in detail the function of PHP is diverse and functional similarity is a big feature, the same application can be implemented with a variety of functions, which is probably a disadvantage 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.