PhpDate () function output Chinese Year Month Day hour minute second _ PHP Tutorial

Source: Internet
Author: User
Tags echo date iso 8601 iso 8601 format
The phpDate () function outputs the Chinese year, month, day, hour, minute, and second. Today, I output the Chinese year, month, day, hour, minute, and second using a simple date () function, which leads to some questions about the use of the phpdate () function by most data users and detailed descriptions of the parameters of the date () function. Today, I output the Chinese year, month, day, hour, minute, and second using a simple date () function, which leads to some questions about the use of the php date () function by most data users and detailed descriptions of the parameters of the date () function.

Of course, the DATE function of PHP cannot directly output Chinese characters, but you can use the following method to write a function.

The code is as follows:

Function today (){
Date_default_timezone_set ("Asia/Chongqing ");
$ A = date ("Y ");
$ B = date ("m ");
$ C = date ("d ");
$ D = date ("G ");
$ E = date ("I ");
$ F = date ("s ");
Return $. 'year '. $ B. 'month '. $ c. 'Day '. $ d. 'Time '. $ e. 'Min '. $ f. 'second ';}

If echo date ("Y-m-d") appears ");

Alert number:

Warning: date () [function. date]: It is not safe to rely on the system's timezone settings. you are * required * to use the date. timezone setting or the date_default_timezone_set () function. in case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. we selected 'utc' for '8. 0/no DST 'Instead in G: sourcetestceshimktime. php on line 4
I checked the information online to find out the cause. I will share with you the following:
When PHP versions later than PHP5.3 are used, if it is time-related,

"PHP Warning: date () [function. date]: It is not safe to rely on the system's timezone settings. you are * required * to use the date. timezone setting or the date_default_timezone_set () function. in case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. we selected 'utc' for '8. 0/no DST 'Instead in

There are three methods (either of them ):

1. use date_default_timezone_set () in the page header to set date_default_timezone_set ('prc'); // echo date ('Y-m-d H: I: s') in the East eight time zone ');

2. use ini_set ('date. timezone ', 'Asia/Shanghai') in the page header ');

3. modify php. ini. Open php5.ini to search for date. timezone. remove the semicolon and change it to: date. timezone = PRC.

Restart the http service (such as apache2 or iis.

Date function parameters

D. The day of the month, which has two numbers from the leading zero, 01 to 31.

D. The day of the week. The text indicates the three letters Mon to Sun.

The day of month j, with no leading zeros 1 to 31

L ("L" lowercase letter) day of the week, complete text format Sunday to Saturday

N ISO-8601 format number represents the day of the week (PHP 5.1.0 New plus) 1 (Monday) to 7 (Sunday)

The suffix of S after the number of days per month. it can contain 2 characters including st, nd, rd, and th. Can be used with j

The day of the week. The number indicates 0 (Sunday) to 6 (Saturday)

Day 0 to 366 in year z

The week of the year in W ISO-8601 format, starting from Monday every week (new in PHP 4.1.0) 42 (42nd weeks of the year)

F month, complete text format, such as January or March January to December

The month represented by m numbers, with a leading zero from 01 to 12

M: The month Jan to Dec.

N indicates the month with no leading zeros 1 to 12.

T the number of days in a given month from 28 to 31

L whether it is a leap year. if it is a leap year, it is 1; otherwise, it is 0.

O ISO-8601 format year number.

The year in which the four digits of Y are complete, for example, 1999 or 2003.

The year represented by y two digits, for example, 99 or 03.

A lower-case morning and afternoon values: am or pm

A capital value of AM and PM

B Swatch Internet standard: 000 to 999

G-hour, 12-hour format, no leading zero 1 to 12

G-hour, in 24-hour format, no leading 0 to 23

H-hour, 12-hour format, with a leading value of 0 to 12

H-Hour, in 24-hour format, with a leading zero 00 to 23

I have the number of minutes leading to zero from 00 to 59>

S seconds, with a leading zero 00 to 59>

E time zone identifier (new in PHP 5.1.0) for example: UTC, GMT, Atlanta/Azores

When I is running or not, if it is running, it is 1; otherwise, it is 0.

O hours different from Greenwich Mean Time, for example: + 0200

The difference between P and Greenwich Mean Time (GMT). There are colons between hours and minutes, for example: +

T the time zone of the local machine

The number of seconds of the Z time difference offset. The time zone offset to the west of UTC is always negative, and the east of UTC is positive. -43200 to 43200

Date in c ISO 8601 format (new PHP 5): 19: 21 + 00: 00

Date in RFC 822 format: Thu, 21 Dec 2000 16:01:07 + 0200

U obtains the timestamp from the Unix epoch (January 1 1970 00:00:00 GMT) to the current time ().

The date () function of php is very powerful. through the above parameters, you can perform many date Operations. for example, you can obtain the red parameter descriptions marked above to implement the day of the week today!

The extract () function outputs Chinese characters, such as year, month, day, hour, minute, and second. this introduces some questions about the use of the php date () function by most data users, and describes the parameters of the date () function ....

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.