Application of the Php-date (), Time () function

Source: Internet
Author: User
Tags echo date
This article is to share the content of PHP in the date () and time () function of the application, the need for friends can refer to


1, the current timestamp (unit: seconds)


Description: The time () function returns the number of seconds of the current period from the Unix era (January 1 1970 00:00:00 GMT)
Syntax: Time ()
Give me a chestnut:

Time (): Returns the current time of the Unix timestamp echo times ();//For example: 1516332756

2. Ask for the current date

Description: the date () function is used to format the time/date.
Syntax: string Date (string

Timestamp])
Parameters:
Format required. Specifies the format of the timestamp.
Timestamp is optional. Time stamp is specified. The default is the current date and time.
Give me a chestnut:


The following lines of code will have the same output (the style may be different) echo date (' y-m-d h:i:s '),//2018-01-19 11:56:08echo date (' y-m-d h:i:s ', Time ()),//2018-01-19 11:56:08echo date (' Ymd his ', Time ()),//20180119 115608echo date (' Y.m.d h:i:s ', Time ()),//2018.01.19 11:56:08

3, today, yesterday, tomorrow, the time stamp of the simple implementation method

Echo strtotime (' Now '), ' <br> ';//Present: 1516334071echo strtotime (' Today '), ' <br> ';//Today: 1516291200echo Strtotime (' Tomorrow '), ' <br> ';//Tomorrow: 1516377600echo strtotime (' Yesterday '), ' <br> ';//yesterday: 1516204800echo $ Time_remain=strtotime (' Tomorrow ')-time ();//number of seconds left today-output: 43362

4. How to achieve the date of recent days

echo "Today:". Date ("y-m-d"). " <br> "echo" Yesterday: ". Date (" Y-m-d ", Strtotime (" 1 day ")," <br> ";     echo "Tomorrow:". Date ("Y-m-d", Strtotime ("+1 Day")). " <br> "echo" A week ago: ". Date (" Y-m-d ", Strtotime (" 1 Week "))." <br> "echo" A week later: ". Date (" Y-m-d ", Strtotime (" +1 Week "))." <br> "echo" One months ago: ". Date (" Y-m-d ", Strtotime (" Last month ")." <br> ";     echo "One months later:". Date ("Y-m-d", Strtotime ("+1 Month")). " <br> "; echo "Next week Four:". Date ("Y-m-d", Strtotime ("next Thursday")). " <br> "echo" Ten years later: ". Date (" Y-m-d ", Strtotime (" +10 Year "))." <br> "; The function of the Strtotime () function is to parse a datetime description into a Unix timestamp

5. Today is the day of the week

Get the day of the Week (English) echo date ("L");//Can get English for the week such as Sundayecho date ("w");//This can be obtained for the number of weeks such as ..., note 0 is Sunday. Get today's Day of the Week (Chinese) $weekarray =array ("th", "One", "two", "three", "four", "five", "six"); Echo "Week". $weekarray [Date ("W")];

6. The following parameters are attached to the part date ()

A-"AM" or "PM"
A-"AM" or "PM"
D-A few days, two digits, if less than two is the front 0; such as: "01" to "31"
D-Days of the week, three English letters; such as: "Fri"
F-month, full name in English; such as: "January"
H-12 hours of the hour; such as: "01" to "12"
H-hour of 24-hour system; such as: "00" to "23"
G-12 hours of the hour, less than two digits do not fill 0; such as: "1" to 12 "
G-24 hours of the hour, less than two does not fill 0; such as: "0" to "23"
I-minute; such as: "00" to "59"
J-A few days, two digits, if less than two bits do not fill 0; such as: "1" to "31"
L-Day of the week, English full name; such as: "Friday"
M-month, two digits, if less than two digits in front of 0; such as: "01" to "12"
N-month, two digits, if less than two digits does not fill 0; such as: "1" to "12"
M-month, three letters of English; such as: "Jan"
S-second; such as: "00" to "59"
S-End With English ordinal number, two English letters; such as: "th", "nd"
T-the number of days in the specified month; such as: "28" to "31"
U-Total number of seconds
W-Number of days of the week, such as: "0" (Sunday) to "6" (Saturday)
Y-year, four digits; such as: "1999"
Y-year, two digits; such as: "99"
Z-the day ordinal of a year; such as: "0" to "365"

1, the current timestamp (unit: seconds)

Description: The time () function returns the number of seconds of the current period from the Unix era (January 1 1970 00:00:00 GMT)
Syntax: Time ()
Give me a chestnut:

Time (): Returns the current time of the Unix timestamp echo times ();//For example: 1516332756

2. Ask for the current date

Description: the date () function is used to format the time/date.
Syntax: string Date (string

Timestamp])
Parameters:
Format required. Specifies the format of the timestamp.
Timestamp is optional. Time stamp is specified. The default is the current date and time.
Give me a chestnut:


The following lines of code will have the same output (the style may be different) echo date (' y-m-d h:i:s '),//2018-01-19 11:56:08echo date (' y-m-d h:i:s ', Time ()),//2018-01-19 11:56:08echo date (' Ymd his ', Time ()),//20180119 115608echo date (' Y.m.d h:i:s ', Time ()),//2018.01.19 11:56:08

3, today, yesterday, tomorrow, the time stamp of the simple implementation method

Echo strtotime (' Now '), ' <br> ';//Present: 1516334071echo strtotime (' Today '), ' <br> ';//Today: 1516291200echo Strtotime (' Tomorrow '), ' <br> ';//Tomorrow: 1516377600echo strtotime (' Yesterday '), ' <br> ';//yesterday: 1516204800echo $ Time_remain=strtotime (' Tomorrow ')-time ();//number of seconds left today-output: 43362

4. How to achieve the date of recent days

echo "Today:". Date ("y-m-d"). " <br> "echo" Yesterday: ". Date (" Y-m-d ", Strtotime (" 1 day ")," <br> ";     echo "Tomorrow:". Date ("Y-m-d", Strtotime ("+1 Day")). " <br> "echo" A week ago: ". Date (" Y-m-d ", Strtotime (" 1 Week "))." <br> "echo" A week later: ". Date (" Y-m-d ", Strtotime (" +1 Week "))." <br> "echo" One months ago: ". Date (" Y-m-d ", Strtotime (" Last month ")." <br> ";     echo "One months later:". Date ("Y-m-d", Strtotime ("+1 Month")). " <br> "; echo "Next week Four:". Date ("Y-m-d", Strtotime ("next Thursday")). " <br> "echo" Ten years later: ". Date (" Y-m-d ", Strtotime (" +10 Year "))." <br> "; The function of the Strtotime () function is to parse a datetime description into a Unix timestamp

5. Today is the day of the week

Get the day of the Week (English) echo date ("L");//Can get English for the week such as Sundayecho date ("w");//This can be obtained for the number of weeks such as ..., note 0 is Sunday. Get today's Day of the Week (Chinese) $weekarray =array ("th", "One", "two", "three", "four", "five", "six"); Echo "Week". $weekarray [Date ("W")];

6. The following parameters are attached to the part date ()

A-"AM" or "PM"
A-"AM" or "PM"
D-days, two digits, if less than two digits before 0, such as: "01" to "seven"
D-Day of the week, three English letters, such as: "Fri"
F-month Full name in English; such as: "January"
h-12 hours of the hour, such as: "01" to "three"
H-24 hours of the hour, such as: "00" to ""
g-12 hours, less than two does not fill 0, such as: "1" to 12 " Br>g-24 hours of the hour, less than two digits do not fill 0; such as: "0" to "0"
I-minute, such as: "00" to "a"
J-A few days, two digits, if less than two digits do not fill 1, such as: "From" to "+"
L-Day of the week, English full name, such as: "Friday"
M-month, Two digits, if less than two digits in front of 0; such as: "01" to "three"
N-month, two digits, if less than two digits do not fill 0, such as: "1" to "nine"
M-month, the English alphabet, such as: "Jan"
S-second; for example: "00" to "Sukayin"
S-character Text ordinal, two English letters; such as: "th", "nd"
T-Specify the number of days of the month, such as: "28" to "X"
U-the total number of seconds
W-the number of weeks, such as: "0" (Sunday) to "6" (Saturday)
Y-year, four digits; for example: "1999 "
Y-year, two digits; For example: "365"
Z-the day of the year; For example: "0" to "* * *"

Related Article

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.