Show the starting and ending points of this month, last month, today, and this year

Source: Internet
Author: User
Tags echo date

Show the starting and ending points of this month, last month, today, and this year

The mktime () function returns the Unix timestamp of a date.

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

The parameters can be left empty from right to left. The blank parameters are set to the corresponding current GMT value.

PHP Date () function
The PHP Date () function can format the timestamp as a Date and time with better readability.

Syntax
Date (format, timestamp) parameter description
Format is required. The format of the specified timestamp.
Optional. The specified timestamp. The default value is the current date and time.


The mktime and date functions are briefly described above. Let's take a look at the date calculation using their instances today, last month, and next month.

 

$ T = time ();
$ T1 = mktime (0, 0, 0, date ("m", $ t), date ("d", $ t), date ("Y", $ t ));
$ T2 = mktime (0, 0, 0, date ("m", $ t), 1, date ("Y", $ t ));
$ T3 = mktime (, 0, date ("m", $ t)-, date ("Y", $ t ));
$ T4 = mktime (, 1, date ("Y", $ t ));
$ E1 = mktime (, 59, date ("m", $ t), date ("d", $ t), date ("Y", $ t ));
$ E2 = mktime (, 59, date ("m", $ t), date ("t"), date ("Y", $ t ));
$ E3 = mktime (, 59, date ("m", $ t)-1, date ("t", $ t3), date ("Y ", $ t ));
$ E4 = mktime (, 31, date ("Y", $ t ));

Refer to the mktime () function

Parameters Description
Hour Optional. The specified hour.
Minute Optional. Minutes.
Second Optional. Specified seconds.
Month Optional. Indicates the month in number.
Day Optional. Specified day.
Year Optional. Specified year. In some systems, the valid value ranges from 1901 to 2038. However, this restriction does not exist in PHP 5.
Is_dst

Optional. If the time is in the daylight saving time (DST) period, it is set to 1; otherwise, it is set to 0. If it is unknown, it is set to-1.

The is_dst parameter has been deprecated since 5.1.0. Therefore, the new time zone processing feature should be used.

 

// Test
Echo date ("current Y-m-d H: I: s", $ t). "$ t <br> ";
Echo date ("Today's start point Y-m-d H: I: s", $ t1). "$ t1 <br> ";
Echo date ("starting point of this month Y-m-d H: I: s", $ t2). "$ t2 <br> ";
Echo date ("starting from last month Y-m-d H: I: s", $ t3). "$ t3 <br> ";
Echo date ("This year's start point Y-m-d H: I: s", $ t4). "$ t4 <br> ";
// Test
Echo date ("end today Y-m-d H: I: s", $ e1). "$ e1 <br> ";
Echo date ("end of this month Y-m-d H: I: s", $ e2). "$ e2 <br> ";
Echo date ("end of last month Y-m-d H: I: s", $ e3). "$ e3 <br> ";
Echo date ("end of this year Y-m-d H: I: s", $ e4). "$ e4 <br> ";
Result:
Currently 15:42:55 1306222975
Starting from 00:00:00 1306166400
Starting from 00:00:00 1304179200
Starting from last month 00:00:00 1301587200
Starting from 00:00:00 this year, 1293811200
End of today: 23:59:59 1306252799
End of this month: 23:59:59 1306857599
Last month's endpoint 23:59:59 1304179199
End of this year 23:59:59 1325347199

Let's take a look at the date function.

Parameters Description
Format Required. The format of the specified timestamp.
Timestamp Optional. The specified timestamp. The default value is the current date and time.

PHP date-format date
The first parameter of the date () function specifies how to format the date/time. It uses letters to indicate the date and time formats. Some available letters are listed here:

Day in d-month (01-31)
M-current month, in numbers (01-12)
Y-current year (four digits)
You can find all the letters that can be used in the format parameters in our PHP Date reference manual.

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.