PHP mktime () function

Source: Internet
Author: User
Tags echo date php tutorial

PHP date/time function
Definitions and usage
The Mktime () function returns a Unix timestamp for a date.

The parameter always represents the GMT date, so IS_DST has no effect on the result.

The parameters can be left-to-right, and the empty arguments will be set to the appropriate current GMT value.

Grammar
Mktime (HOUR,MINUTE,SECOND,MONTH,DAY,YEAR,IS_DST) parameter description
Hour optional. Set hours.
Minute optional. Specify minutes.
Second Optional. Specified seconds.
Month optional. A month that is specified in numbers.
Day is optional. Stipulated day.
Year is optional. Set year. On some systems, the legal value is between 1901-2038. However, there is no such limit in PHP 5.
Is_dst Optional. If time is in daylight saving time (DST), set to 1, otherwise set to 0, if unknown, set to-1.

Since 5.1.0, IS_DST parameters have been discarded. Therefore, you should use the new time zone processing attributes.

Tips and comments
Note: Before PHP 5.1, false is returned if the function's arguments are illegal.
Example
The Mktime () function is useful for date operations and validation. It can automatically correct the input that crosses the line:

<?php Tutorial
Echo (Date ("M-d-y", Mktime (0,0,0,12,36,2001));
Echo (Date ("M-d-y", Mktime (0,0,0,14,1,2001));
Echo (Date ("M-d-y", Mktime (0,0,0,1,1,2001));
Echo (Date ("M-d-y", Mktime (0,0,0,1,1,99));
?> output:

jan-05-2002
feb-01-2002
jan-01-2001
jan-01-1999


Example #1 mktime () basic Example

<?php
Set The default timezone to use. Available as of PHP 5.1
Date_default_timezone_set (' UTC ');

Prints:july 1, on a Saturday
echo "July 1, is on a". Date ("L", mktime (0, 0, 0, 7, 1, 2000));

Prints something like:2006-04-05t01:02:03+00:00
echo Date (' C ', Mktime (1, 2, 3, 4, 5, 2006));
?>
Mktime () is useful for date calculations and validation because it automatically calculates the range input for the correct value. For example, each of the following lines will produce a string "jan-01-1998"

<?php
echo Date ("M-d-y", mktime (0, 0, 0, 12, 32, 1997));
echo Date ("M-d-y", mktime (0, 0, 0, 13, 1, 1997));
echo Date ("M-d-y", mktime (0, 0, 0, 1, 1, 1998));
echo Date ("M-d-y", mktime (0, 0, 0, 1, 1, 98));
?>


<?php
$lastday = mktime (0, 0, 0, 3, 0, N);
Echo strftime ("Last day in Feb:%d", $lastday); $lastday = mktime (0, 0, 0, 4,-31, 2000);
Echo strftime ("Last day in Feb:%d", $lastday);
?

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.