PHP Date and Time Format

Source: Internet
Author: User

The date and time in PHP are mainly obtained and formatted by the date () function. Although this is frequently used, it is sometimes forgotten or mixed, the summary is as follows...

1. year/month/day 1. Year

Y (2010): uppercase y indicates four digits of the year.
Y (10): lowercase y indicates two digits of the year

2. Month

F (January): upper-case F indicates the English full write of the month (no lower-case F)
M (Jan): uppercase M indicates the three abbreviations of a month.
M (01-12): lowercase M indicates the number of the month, with the leading
N (1-12): lowercase n indicates the number of the month, no leading

3. Daily

J (1-31): lowercase J indicates the date of the month, no leading (no uppercase J)
D (01-31): lowercase D indicates the date of the month, with a forward sign (no capital D)
S (St, Nd, RD, and th): uppercase s indicates the suffix of the date, depending on the date number

4. Instances

Y-m-J (2007-02-6)
Y-n-J (07-2-6)
Y-m-J (2007-feb-6)
Y-m-D (2007-02-06)
Y-F-js (2007-february-6th)

Ii. Hour: minute: Second 1. Hour

G (1-12): lowercase G indicates the number of hours in the 12-hour format. No leading 0
H (01-12): lowercase h indicates the number of hours in the 12-hour format, with a leading 0
G (0-23): uppercase G indicates the number of hours in the 24-hour format. No leading 0
H (01-23): H in uppercase represents the number of hours in the 24-hour format, with a leading 0

A Indicates lower-case "am" and "PM" (morning and afternoon)
A Indicates uppercase "am" and "PM"

2. Minute: Second

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

I (1-60): lowercase I indicates the score
S (1-60): lowercase s indicates seconds

3. Instance

G: I: S A (5:56:57 am)
H: I: S A (05:56:57 am)
G: I: S (14:02:26)

3. leap year, Week, and day
  1. Capital L indicates whether this year is a leap year. If it is true, 1 is returned. Otherwise, 0 is returned.
  2. Lowercase W indicates the day of the week, expressed in numbers
  3. In upper case, W indicates the number of weeks in a year.
  4. Lowercase t indicates the number of days in the current month
  5. Lowercase Z indicates that today is the day of the year
4. Others
  1. Uppercase t indicates the time zone setting of the server, for example, UTC
  2. If I is used to determine whether the current value is success, 1 is returned for true. Otherwise, 0 is returned.
  3. 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.
  4. Lowercase c Represents the iso8601 date, the date format is YYYY-MM-DD, with the letter T to interval the date and time, the time format is hh: mm: SS, the time zone uses Greenwich Mean Time (GMT) if the value is 2007-02-06t14: 24: 43 + 00: 00
  5. Lowercase R indicates the rfc822 date. For example, if the value is Tue, 06 Feb 2007 14:25:52 + 0000

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.