PHP timestamp Strtotime () using methods and techniques _php instance

Source: Internet
Author: User
Tags current time echo date
In PHP I want to get a timestamp there are many ways, the most common is to use the time function and the strtotime () function to convert the date into a timestamp, I would like to share the time stamp function strtotime usage.


gets the specified date of year into the timestamp:


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


examples are as follows:


Copy Code code as follows:

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



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


converts the current year to time stamp: The PHP timestamp function gets the Unix timestamp of the current date,


examples are as follows:


Copy Code code as follows:

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



: Returns the time stamp of a minute and a minute on the current date.


converts the timestamp to month Day:


Copy Code code as follows:

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



Case


Copy Code code as follows:

<?php
/*
From:http://www.jb51.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 to get English text date time


facilitates comparison by using date to convert a timestamp to a system time with a specified timestamp


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


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) Prints 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")) Result: 2009-01-29 09:40:25


(4) Prints 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) Prints the 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")) Result: 2009-01-29 00:00:00


(6) Prints the 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")) Result: 2009-01-15 00:00:00


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 the mktime () or date () format date time to get the specified timestamp, to achieve the required date time.


you may be interested in the 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.