PHP timestamp function strtotime () Usage tips

Source: Internet
Author: User
Tags current time echo date

Gets the specified year date into the timestamp:

PHP timestamp function gets the UNIX timestamp strtotime of the specified date (' 2012-12-7 ')

Examples are as follows:

The code is as follows Copy Code

<?php echo strtotime (' 2012-12-7 '); Results: 1354838400?>

Description: Returns December 7, 2012 0:0 0 seconds timestamp.


Converts the current month day into a timestamp:

The PHP timestamp function gets the current date's Unix timestamp,

Examples are as follows:

The code is as follows Copy Code


<?php Echo $time =intval (Time ());?>

Description: Returns the time stamp of the current time of the month and the day.


Converts a timestamp to the date of the year:

The code is as follows Copy Code

<?php
echo Date ("Y-m-d h:i:s", Intval (Time ()));
?>

Cases

The code is as follows Copy Code
<?php
/*
From:http://www.111cn.net
@date: 2013-02-22
*/
Echo Strtotime ("Now"), "n";
Echo Strtotime ("September"), "n";
Echo strtotime ("+1 Day"), "n";
Echo strtotime ("+1 Week"), "n";
Echo strtotime ("+1 Week 2 days 4 hours 2 Seconds"), "n";
Echo Strtotime ("next Thursday"), "n";
Echo Strtotime ("Last Monday"), "n";
?>

PHP timestamp function gets English text date time


Easy to compare, using date to convert the timestamp to the system time with the specified timestamp

(1) Print tomorrow at this time the timestamp strtotime ("+1 Day")

Current Time: Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25

Specified time: echo date ("Y-m-d h:i:s", Strtotime ("+1 Day") Results: 2009-01-23 09:40:25

(2) Print the timestamp strtotime ("-1 day") at this time yesterday

Current Time: Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25

Specified time: echo date ("Y-m-d h:i:s", Strtotime ("1 day")) Results: 2009-01-21 09:40:25

(3) Print the timestamp strtotime ("+1 Week") at this time next week

Current Time: Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25

Specified time: echo date ("Y-m-d h:i:s", Strtotime ("+1 Week") Results: 2009-01-29 09:40:25

(4) Print the timestamp strtotime ("-1 week") at this time last week

Current Time: Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25

Specified time: echo date ("Y-m-d h:i:s", Strtotime ("1 week")) Results: 2009-01-15 09:40:25

(5) Print a timestamp strtotime ("next Thursday") that specifies the next day of the week

Current Time: Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25

Specified time: echo date ("Y-m-d h:i:s", Strtotime ("next Thursday") Results: 2009-01-29 00:00:00

(6) Print a timestamp strtotime ("last Thursday") that specifies the previous week

Current Time: Echo Date ("Y-m-d h:i:s", Time ()) Result: 2009-01-22 09:40:25

Specified time: echo date ("Y-m-d h:i:s", Strtotime ("last Thursday") Results: 2009-01-15 00:00:00

The above PHP timestamp function example know the source sky, Strtotime can be any English text of the date and time description of the Unix timestamp, we combine mktime () or date () format date time to get the specified time stamp to achieve the required date time.

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.