PHP Strtotime converts day dates to time stamps

Source: Internet
Author: User
Tags current time echo date

/*
Convert Day date to time stamp
Strtotime (time,now) parameter description
Time to specify the string to parse.
Now is the time stamp used to calculate the return value. If this argument is omitted, the current time is used.

<?php
Echo Strtotime ("Now"), "";
Echo Strtotime ("September 2000"), "";
Echo strtotime ("+1 Day"), "";
Echo strtotime ("+1 Week"), "";
Echo strtotime ("+1 Week 2 days 4 hours 2 Seconds"), "";
Echo Strtotime ("next Thursday"), "";
Echo Strtotime ("Last Monday"), "";
?>

<?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 o F Y h:i:s A ', $timestamp);
}
?>

And look at the strtotime example
*/
echo strtotime (' 2010-2-14 '), "<br/>";
echo Date (' y-m-d ', strtotime (' 2010-2-14 '));

Output value

1266076800
2010-02-14

You should be in Strtotime (), and you decide what you can't do. For example
<?php

# on 2/8/2010
Date (' m/d/y ', Strtotime (' Day ')); # 02/01/10
Date (' m/d/y ', Strtotime (' Last Day ')); # 02/28/10
Date (' m/d/y ', Strtotime (' Last day next month '); # 03/31/10
Date (' m/d/y ', Strtotime (' Last day month ')); # 01/31/10
Date (' m/d/y ', Strtotime (' 2009-12 last Day ')); # 12/31/09-this doesn ' t work if you reverse the order of the Year and month
Date (' m/d/y ', Strtotime (' 2009-03 last Day ')); # 03/31/09
Date (' m/d/y ', strtotime (' 2009-03 ')); # 03/01/09
Date (' m/d/y ', Strtotime (' Last day of March 2009 ')); # 03/31/09
Date (' m/d/y ', Strtotime (' Last day of March ')); # 03/31/10
?>

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.