PHP Date function in-depth learning _php tutorial

Source: Internet
Author: User
Tags echo date local time
The format of the date in the programming is often not good control, PHP date function is more commonly used, so I studied the PHP date function, here to take out and share with you, hope to be useful to everyone. PHP datetime function 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 represents the year four digits, while lowercase y represents the two digits of the year, the lowercase m represents the number of the month (with the leading), and the lowercase n indicates the month number without leading.

 
  
  
  1. echo Date (' y-m-j ');
  2. 2007-feb-6
  3. echo Date (' y-m-d ');
  4. 2007-02-06

The uppercase M represents the 3 abbreviation characters of the month, while the lowercase m represents the number of the month (with leading 0); J with no upper case, only lowercase J for the date of the month, no leading o, or lowercase D if the month with leading is required.

 
  
  
  1. echo Date (' y-m-j ');
  2. 2007-feb-6
  3. echo Date (' Y-f-js ');
  4. 2007-february-6th

Uppercase M represents the 3 abbreviated characters of the month, while uppercase F indicates the full written English of the month. (no lowercase f) uppercase S denotes the suffix of the date, such as "St", "nd", "rd", and "th", depending on the date number. Summary: Indicates that the year can be capitalized with Y and lowercase y, indicating that the month can be in uppercase F, uppercase M, lowercase m, and lowercase n (two ways of representing characters and numbers, respectively); The day can be in lowercase d and lowercase j, and uppercase s represents the suffix of the date.


2, Hours: minutes: seconds

By default, the PHP interpretation is displayed as "Greenwich Mean Time", which differs from our local time by 8 hours.

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

The lowercase g represents a 12-hour system without a leading 0, while the lowercase h indicates a 12-hour system with a leading 0. When using the 12-hour system, it is necessary to indicate that in the afternoon, lowercase a represents the lowercase "am" and "PM", and uppercase a denotes uppercase "AM" and "PM". The uppercase G represents the 24-hour hour, but without the preamble, and the uppercase H indicates a leading 24-hour hour. Summary: The letter G means the hour without leading, the letter h for the hour with the leading; lowercase g, h for 12-hour, uppercase G, h for 24-hour system. The above is a simple PHP date function year-month-day, when: minute: the introduction of the second, I hope to help everyone.


http://www.bkjia.com/PHPjc/446513.html www.bkjia.com true http://www.bkjia.com/PHPjc/446513.html techarticle in programming the format of the date is often not good control, PHP date function is more commonly used, so I studied the PHP date function, here to take out and share with you, I hope the big ...

  • 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.