[Consolidate PHP Basics] PHP date function, consolidate phpdate Function

Source: Internet
Author: User
Tags php basics

[Consolidate PHP Basics] PHP date function, consolidate phpdate Function

Original article address

Outline:

1. Introduction

2. Sample Code

3. References

 

 

1. Introduction

 

Today, I saw a piece of code.

$ TimeNew = date ('n month j ', strtotime ($ oldTime ));

I am a little confused. I have queried the PHP manual and date functions and sorted them as follows.

 

2. Sample Code

 

Add date_default_timezone_set (PRC);/* to set the time to Beijing time. php5 defaults to Greenwich mean time */date (): "am" or "pm" A: "AM" or "PM" d: days, double digits. If not, add zero. From "01" to "31" D: the day of the week, with three English letters, such as: "Fri" F: Month, full English name, such as: "January" h: 12-hour, from "01" to "12" H: 24 hours, from "00" to "23" g: 12 hours, no zeros; from "1" to "12" G: hour in 24-hour format, do not fill in zero; from "0" to "23" j: a few days, not zero; from "1" to "31" l: day of the week, full English name, such as: "Friday" m: month, two digits, from "01" to "12" n: month, double-digit, not zero; from "1" to "12" M: month, 3 English letters; for example: "Jan" s: seconds; from "00" "59" S: ending with an English sequence, two English letters, such as: "21th" t: specifies the number of days of the month, from "28" to "31" U: Total number of seconds w: number of weeks, from "0 (Sunday)" to "6 (Saturday)" Y: year, four digits y: year, two digits z: The day of the year; from "1" to "366" ================================ ====================================== 1, year-month-Day indicates that the year can be uppercase Y and lowercase y; indicates that a month can be written in uppercase letters (F), uppercase letters (M), lowercase letters (m), and lowercase letters (n). It can be written in lowercase letters (d) and lowercase letters (j, uppercase S indicates the suffix of the date. Echo date ('Y-m-J'); 2007-02-6echo date ('Y-n-J'); 07-2-6 capital Y indicates four digits of the year, lowercase y indicates two digits of the Year. lowercase m indicates the number of the month (with the leading digit), while lowercase n indicates the number of the month without the leading digit. Echo date ('Y-M-J'); 2007-Feb-6echo date ('Y-m-d'); 2007-02-06 Capital M indicates three abbreviations of the month, in lower case, m indicates the number of the month (with the leading 0); In less case, J indicates the date of the month, and no leading o; use lowercase d if the month has a prefix. Echo date ('Y-M-J'); 2007-Feb-6echo date ('Y-F-js'); 2007-February-6th capital M represents three abbreviations of the month, in upper case, F indicates the English full write of the month. (No lowercase f) uppercase S indicates the suffix of the date, such as "st", "nd", "rd", and "th". For details, see the date number. 2, hour: minute: by default, PHP interprets the display time as "Greenwich Mean Time", which is 8 hours different from our local time. Echo date ('G: I: s A'); 5:56:57 amecho date ('H: I: s A'); 05:56:57 lowercase g indicates 12-hour format, no leading 0, the lower-case h indicates that there is a 12-hour leading 0. When the 12-hour format is used, it indicates that upper afternoon, lower case a indicates lower case "am" and "pm", and upper case A indicates upper case "AM" and "PM ". Echo date ('G: I: s'); 14:02:26 uppercase G indicates the number of hours in the 24-hour system, but without leading; use uppercase H to indicate the number of hours in the 24-hour format with the leading character. The letter g indicates that the hour does not have the leading character, and the letter h indicates that the hour has the leading character. The lowercase g and h indicate that the 12-hour format, uppercase G and H indicate the 24-hour format. 3. leap year, Week, and day echo date ('l'); this year's leap year: 0 echo date ('l'); today is: Tuesdayecho date ('D '); today is: Tue capital L indicates whether to determine the leap year of the Year, Boolean value, True returns 1; otherwise, 0; lowercase l indicates the day of the week in full (Tuesday ); however, uppercase D is used to represent the three abbreviation of the day of the week (Tue ). Echo date ('W'); today's week: 2 echo date ('W'); this week is the first week of the year. lowercase w indicates the day of the week, in the digit format, W indicates the number of weeks in a year. echo date ('T'); this month is 28 days echo date ('Z '); today is the second day of this year. lowercase t indicates the number of days in the current month. lowercase z indicates that today is the fourth day of this year. Other echo date ('T '); UTC capital T indicates that the server's time zone is set to echo date ('I'); capital I indicates that 1 is returned if the current value is success, otherwise, the value is 0 echo date ('U'). The upper-case U table shows the total number of seconds from January 1, January 1, 1970 to the present, which is the Unix timestamp of the UNIX time era. Echo date ('C'); 2007-02-06T14: 24: 43 + 00: 00 lowercase c Represents the ISO8601 date, the date format is YYYY-MM-DD, with the letter T to separate the date and time, the time format is HH: MM: SS, and the time zone is expressed by GMT deviation. Echo date ('R'); Tue, 06 Feb 2007 14:25:52 + 0000 lowercase r indicates the RFC822 date. 5. The formatting time echo $ row ["t_time"]; returns the 12: 08: 00 echo date ("Y-m-d ", strtotime ($ row ["t_time"]); returns the note. Because the time obtained by $ row ["t_time"] is already a string, therefore, you need to use strtotime (string to timestamp) to convert it. Otherwise, the error "1970-01-01" will be output.

 

3. References 

 

1) date function in php Manual

2) date function in W3C

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.