Reprint: PHP timestamp Strtotime () using methods and tricks

Source: Internet
Author: User
Tags echo date timestamp to date

There are several ways in which I want to get timestamps in PHP, and the most common is to use the time function and the strtotime () function to convert dates into timestamps.

Gets the specified month-date conversion to timestamp:
PHP timestamp function Gets the UNIX timestamp of the specified date strtotime (' 2012-12-7 ')

<?php     Echo strtotime (' 2012-12-7 ');//results: 1354838400?>

Note: Return December 7, 2012 0:0 0 seconds timestamp.

Converts the current month day to timestamp: the PHP timestamp function gets the Unix timestamp for the current date,
Examples are as follows:

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

Note: Returns the timestamp of the current time, month, day, and seconds.

Convert the timestamp to date:

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

Cases:

<?php/*from:http://www.jb51.net@date:2013-02-22*/echo strtotime ("Now"), "n"; Echo Strtotime ("September 2000"), "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 Get English text date time
Easy to compare, use date to convert time stamp to system time with specified timestamp
(1) Print the timestamp for tomorrow at this time Strtotime ("+1 Day")
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25
Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("+1 Day") Results: 2009-01-23 09:40:25
(2) Print the timestamp at this time yesterday Strtotime ("-1 day")
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25
Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("1 day") Results: 2009-01-21 09:40:25
(3) Print timestamp strtotime ("+1 Week") at this time next week
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25
Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("+1 Week") Results: 2009-01-29 09:40:25
(4) Print timestamp strtotime ("1 week") at this time last week
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25
Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("1 Week") Results: 2009-01-15 09:40:25
(5) Print the time stamp specified next week strtotime ("next Thursday")
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 2009-01-22 09:40:25
Time Specified: Echo date ("Y-m-d h:i:s", Strtotime ("next Thursday") Results: 2009-01-29 00:00:00
(6) Print the timestamp strtotime ("last Thursday") specified on the previous day of the week
Current Time: Echo Date ("Y-m-d h:i:s," time ()) Results: 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
Above PHP Timestamp Function example know the source of the sky, Strtotime can be any English text date and time description to the Unix timestamp, we combine mktime () or date () format date time to get the specified timestamp, the required date time.

Reprint: PHP timestamp Strtotime () using methods and tricks

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.