PHP timestamp Strtotime () using methods and tricks

Source: Internet
Author: User
Tags timestamp to date

in PHP I want to get timestamps in a number of ways, the most common is to use the time function and Strtotime () function to convert the date into a timestamp, let me share with you the timestamp function strtotime usage. Gets the specified month-date conversion to timestamp: PHP timestamp function gets the UNIX timestamp for the specified dateStrtotime(' 2012-12-7 'examples are as follows:<?phpEcho Strtotime(' 2012-12-7 ');//results: 1354838400?>Note: Return December 7, 2012 0:0 0 seconds timestamp. Convert current Month day to timestamp: the PHP timestamp function gets the Unix timestamp for the current date, as shown in the following example:<?phpEcho $time=intval( Time());?>returns the timestamp of the current time, month, day, and seconds. Convert the timestamp to date:<?PHPEcho Date("Y-m-d h:i:s",intval( Time())); ?>Example:
<?php@Date: 2014-02-22Echo Strtotime("Now"), "n";Echo Strtotime("Ten 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 the English text date time is easy to compare, use date to convert the timestamp with the specified timestamp to the system time (1) Print the timestamp for tomorrow at this time Strtotime ("+1Day ") Current time:Echo Date("Y-m-d h:i:s", Time()) Results: 2014-01-22 09:40:25Specify time:Echo Date("Y-m-d h:i:s",Strtotime("+1 Day")) Result: 2014-01-23 09:40:25(2) Print the timestamp at this time yesterday Strtotime ("-1Day ") Current time:Echo Date("Y-m-d h:i:s", Time()) Results: 2014-01-22 09:40:25Specify time:Echo Date("Y-m-d h:i:s",Strtotime("-1 day")) Result: 2014-01-21 09:40:25(3) Print the timestamp of the next week at this time Strtotime ("+1Week ") Current time:Echo Date("Y-m-d h:i:s", Time()) Results: 2014-01-22 09:40:25Specify time:Echo Date("Y-m-d h:i:s",Strtotime("+1 Week")) Result: 2014-01-29 09:40:25(4) Print timestamp at this time last week strtotime ("-1Week ") Current time:Echo Date("Y-m-d h:i:s", Time()) Results: 2014-01-22 09:40:25Specify time:Echo Date("Y-m-d h:i:s",Strtotime("-1 Week")) Result: 2014-01-15 09:40:25(5) Print the time stamp specified next week strtotime ("NextThursday ") Current time:Echo Date("Y-m-d h:i:s", Time()) Results: 2014-01-22 09:40:25Specify time:Echo Date("Y-m-d h:i:s",Strtotime(”NextThursday ")) Results: 2014-01-29 00:00:00(6Prints the timestamp strtotime ("last Thursday") Current time of the previous week:Echo Date("Y-m-d h:i:s", Time()) Results: 2014-01-22 09:40:25Specify time:Echo Date("Y-m-d h:i:s",Strtotime("last Thursday")) Result: 2014-01-15 00:00:00above PHP timestamp function example know the source of the sky, Strtotime can be any English text date and time description of the Unix timestamp,
We use the mktime () or date () format date time to get the specified timestamp, and the date time required to implement it.

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.