PHP Time and date operation Combat _php Tutorial

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


2.mktime (); Set time


3.date (); Detailed information about the time of acquisition


Representative String Description Example Output
Years:
Y Established (4-bit) 2011
Y Established (2-bit) 11
Month:
M month, less than two-bit complement 0 (01~12) 01
N month, less than two digits do not fill 0 (1~12) 1
T A total of several days this month (1~31) 31
M English month name (abbreviation) Jan
F English month name (full name) January
Day:
D Date, less than two-bit complement 0 (01~31) 01
J Date, less than two digits not 0 (01~31) 1
Week:
W Number of weeks, (with 0~6 for one to day) 0
D Weekday Name (abbreviated) Sun
L Week name (full name) Sunday
When
H 24 o'clock hours, less than two-bit complement 0 (00~23) 07
G 24 o'clock hours, less than two non-complement 0 (0~23) 7
H 12 o'clock hours, less than two-bit complement 0 (01~12) 07
G 12 o'clock hours, less than two non-complement 0 (1~12) 7
Score of
I Minutes, less than two bits complement 0 (00~59) 40
Seconds:
S seconds, less than two bit 0 (00~59) 45
S seconds, less than two bits complement 0 (00~59) plus English order 45th
Last afternoon:
A Uppercase AM/PM Am
A lowercase am/pm Am
Other:
U 1970/1/1 00:00:00 to the total number of seconds in the specified day 1156780800
Z The first day of the Year (0~365) 255

* Red bottom represents commonly used parameters

Some common uses:
1. Get the total number of seconds from 0 minutes 0 seconds to today, 0 hours January 1, 1970:
Copy CodeThe code is as follows:
echo Date ("U", Mktime (0,0,0,date ("Y"), Date ("M"), Date ("D"));
?>

2. Get the total number of seconds to 7 days before today:
Copy CodeThe code is 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 "Specified time is 7 days before today";
}
Else
{
echo "Specified time is over 7 days before today";
}
?>

http://www.bkjia.com/PHPjc/324112.html www.bkjia.com true http://www.bkjia.com/PHPjc/324112.html techarticle Commonly used time functions: 1.time ();///Get the total number of seconds from 1970/1/1 00:00:00 to now? Echo time (); 2.mktime (); Set the time? Echo Date ("U", Mktime (0,0,0,1,20,2011));//Output ...

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