PHP date function date ()-PHP Tutorial

Source: Internet
Author: User
PHP date function date. In programming, the date format is often difficult to control, and PHP date functions are usually used. so I have studied the PHP date functions and will share them with you here, I hope that the date format in the major programming process is often difficult to control, and PHP date functions are still quite common. so I have studied the PHP date functions and will share them with you here, I hope it will be useful to you. PHP date and time functions date ()

1, year-month-day

 
 
  1. echo date('Y-m-j');
  2. 2007-02-6
  3. echo date('y-n-j');
  4. 07-2-6

Uppercase Y indicates four digits of the year, while 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.

 
 
  1. echo date('Y-M-j');
  2. 2007-Feb-6
  3. echo date('Y-m-d');
  4. 2007-02-06

Uppercase M indicates the three abbreviated characters of the month, while lowercase m indicates the number of the month (with the leading 0). without uppercase J, only lowercase j indicates the date of the month, no leading o; use lowercase d if the month has a leading character.

 
 
  1. echo date('Y-M-j');
  2. 2007-Feb-6
  3. echo date('Y-F-jS');
  4. 2007-February-6th

Uppercase M indicates the three abbreviated characters of the month, while uppercase F indicates the full English writing 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. Summary: The year can be uppercase Y and lowercase y; the month can be uppercase F, uppercase M, lowercase m, and lowercase n (two types of characters and numbers respectively ); indicates the date suffix.


2, hour: minute: Second

By default, PHP interprets the display time as "Greenwich Mean Time", which is 8 hours different from our local time.

 
 
  1. echo date('g:i:s a');
  2. 5:56:57 am
  3. echo date('h:i:s A');
  4. 05:56:57 AM

Lowercase g indicates the 12-hour system, with no leading 0, while lowercase h indicates the 12-hour system with 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 ". Uppercase G indicates the number of hours in the 24-hour format, but does not contain the leading value. uppercase H indicates the number of hours in the 24-hour format. Conclusion: the letter g indicates that the hour does not have a leading character, and the letter h indicates that the hour has a leading character; the lowercase g, h indicates 12 hours, and the uppercase G and H indicate 24 hours. The above is a simple PHP date function year-month-day, hour: minute: second introduction, hope to help everyone.


...

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.