PHP Time and date operation combat _php skills

Source: Internet
Author: User
Tags echo date month name set time time and date
Commonly used time functions:
1.time (); The total number of seconds from 1970/1/1 00:00:00 to today

<?echo time ();? >
2.mktime (); Set time

<?echo date ("U", Mktime (0,0,0,1,20,2011));/Output January 1, 1970 0:0 0 seconds to January 20, 2011 0:0 0 seconds Total seconds//mktime parameters: Mktime (time, minutes, seconds, months, days) , years);//often combined with date ("U", Mktime (time, minute, second, month, day, year));? >
3.date (); More information on getting time

<?echo date ("y-m-d h:i:s")//Output year-month-day: minutes: seconds;//Fill parameters Please refer to the table below; >

represents a String Description Example Output
Years:
Y Siyuanyan (4-bit) <?=date ("Y")?> 2011
Y Siyuanyan (2-bit) <?=date ("Y")?> 11
Month:
M month, less than two-digit supplement 0 (01~12) <?=date ("M")?> 01
N month, less than two digits not complement 0 (1~12) <?=date ("n")?> 1
T A total of several days this month (1~31) <?=date ("T")?> 31
M English month name (abbreviation) <?=date ("M")?> A few.
F English month name (full name) <?=date ("F")?> January
Day:
D Date, less than two-digit complement 0 (01~31) <?=date ("D")?> 01
J Date, less than two digits not complement 0 (01~31) <?=date ("J")?> 1
Week:
W The week of the numeral type, (with 0~6 represents one to day) <?=date ("W")?> 0
D Week name (abbreviation) <?=date ("D")?> Sun
L Weekday name (full name) <?=date ("L")?> Sunday
When
H 24 o'clock hours, less than two-digit supplement 0 (00~23) <?=date ("H")?> 07
G 24 o'clock hours, less than two-digit 0 (0~23) <?=date ("G")?> 7
H 12 o'clock hours, less than two-digit supplement 0 (01~12) <?=date ("H")?> 07
G 12 o'clock hours, less than two-digit 0 (1~12) <?=date ("G")?> 7
Part
I Minutes, less than two-digit complement 0 (00~59) <?=date ("I")?> 40
Seconds:
S seconds, less than two-digit complement 0 (00~59) <?=date ("s")?> 45
S seconds, less than two bits complement 0 (00~59) plus English order <?=date ("S")?> 45th
Last afternoon:
A Capital AM/PM <?=date ("A")?> Am
A lowercase am/pm <?=date ("a")?> Am
Other:
U 1970/1/1 00:00:00 to the total number of seconds of the specified day <?=date ("U")?> 1156780800
Z The first day of the Year (0~365) <?=date ("z")?> 255

* Red Bottom represents the commonly used parameters

Some common uses:
1. Get January 1, 1970 0 hours 0 minutes 0 seconds to today's total seconds:
Copy Code code as follows:

?
echo Date ("U", Mktime (0,0,0,date ("Y"), Date ("M"), Date ("D"));
?>

2. Get the total number of seconds from today to the previous 7 days:
Copy Code code as follows:
.
$setTime = Date ("U", Mktime (0,0,0,7,20,2011));
$time = Date ("U", Mktime (0,0,0,date ("M"), Date ("D"), Date ("Y"));
$start = $time -86400*7;
$over = $time +86400*7;
if ($start >= $time && $time <= $over)
{
echo Specifies the time in the 7 days before today ";
}
Else
{
echo "specifies that the time is over 7 days before today";
}
?>

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.