PHP Time Date processing function Usage Summary

Source: Internet
Author: User
Tags current time echo date

PHP time is generally used in the form of large integers is stored and called. The time () function returns a Unix timestamp for the current time.

Definitions and usage

The time () function returns a Unix timestamp for the current time.

Grammar

Time (void) parameter description
void Optional.

Description
Returns the number of seconds since the Unix era (GMT January 1, 1970 00:00:00) to the current time.

Cases

The code is as follows Copy Code

<?php

$t =time ();

$nextWeek = time () + (7 * 24 * 60 * 60); 7 days; Hours; mins; 60secs

Echo $t;

Echo $nextWeek;

?>

Definitions and usage

The strtotime () function resolves the date-time description of any English text to a Unix timestamp.

Grammar

Strtotime (Time,now)

The Strtotime (time,now) function resolves the date-time description of any English text to a Unix timestamp.

The code is as follows Copy Code

<?php

Echo (Strtotime ("Now"));

Echo (Strtotime ("3 October 2005"));

Echo (Strtotime ("+5 hours"));

Echo (Strtotime ("+1 Week"));

Echo (Strtotime ("+1 Week 3 days 7 hours 5 Seconds"));

Echo (Strtotime ("Next Monday"));

Echo (Strtotime ("Last Sunday"));

?>

The date (Format,timestamp) function formats the timestamp as a more readable date and time.

D-Days of the month (01-31)
M-Current month, in Digital (01-12)
Y-the current year (four digits)

The code is as follows Copy Code

<?php

echo Date ("y/m/d");

echo "<br/>";

echo Date ("Y.M.D");

echo "<br/>";

echo Date ("y-m-d");

echo Date (' Y year m month d ', Time ());

?>

Understanding the top three functions can be a good way to manipulate dates in PHP.

Date () function

Use the function date () to implement the

Displayed format: year-month-day hours: minutes: Seconds
Related time parameters:
A-"AM" or "PM"
A-"AM" or "PM"
D-days, two digits, if less than two digits before 0; for example: "01" to " D-Day of the week, three English letters; such as: "Fri"
F-month, the full name of the English language, such as: "January"
h-12 hours of hours, such as: "01" to ""
H-24 hours of hours, such as: "00" to "the"
g-12-hour system Hours, less than two digits does not complement 0; such as: "1" to "
G-24-hour system hours, less than two digits of 0, such as:" 0 "to" ""
I-minutes, such as: "00" to ""
J-days, two digits, if less than two digits do not fill 0, such as: "1" to " L-Days of the week, full name in English; such as: "Friday"
M-month, two digits, if less than two digits in front of the 0; such as: "01" to "the"
N-month, two digits, if less than two digits will not fill 0, such as: "1" to "the"
M-month, three English letters, such as: "Ja N "
S-sec; such as:" 00 "to" ("two")
S--the end of the word plus the English ordinal number, such as: "th", "nd"
T-Specify the number of days of the month, such as: "28" to "
U-Total seconds
W-Numeric type Days of the week, such as: "0" (Sunday) to "6" (Saturday)
Y-year, four digits, such as: "1999"
Y-year, two digits, such as: "" "
Z-the day of the year, such as:" 0 "to" 365 "

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.