PHP strtotime () function time Date conversion _php Tutorial

Source: Internet
Author: User
Tags echo date
The Strtotime () function in PHP parses the datetime description of any English text into a Unix timestamp, a function that we often use, and a friend to refer to.

Grammar
Strtotime (time,now) parameter description
TIME specifies a string of times to parse.
Now is used to calculate the timestamp of the return value. If this argument is omitted, the current time is used.


Example

The code is as follows Copy Code

Echo 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";
?>


Example #2 Failure Check

The code is as follows Copy Code

!--? php
$str = ' not good ';

//Previous to PHP 5.1.0 you would compare with-1, instead of false
if (($timestamp = Strtotime ($str)) = = = = False) {
echo "The string ($STR) is bogus";
} else {
echo "$str = =". Date (' L DS of F Y h:i:s A ', $timestamp);
}
?

I just found out PHP thinks slashes in date-formats aren ' t very European:
(I Guess this is not a B UG, just the IT works. But correct me if I ' m wrong.) !--? php

$date = "06/10/2011 14:28";//6 October 2:28 pm
$otherDate = "06-10-2011 14:28";//6 Octo ber 2:28 PM

Echo $stamp = Strtotime ($date). "
"; Outputs 1307708880
Echo $otherStamp = Strtotime ($otherDate). "
"; Outputs 1317904080

Echo Date ("D-m", $stamp);//Outputs 10-06
Echo date ("D-m", $otherStamp);//outputs 06 -10

;


http://www.bkjia.com/PHPjc/445317.html www.bkjia.com true http://www.bkjia.com/PHPjc/445317.html techarticle The strtotime () function in PHP parses the datetime description of any English text into a Unix timestamp, a function that we often use, and a friend to refer to. Grammar ...

  • 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.