Phpstrtotime () function Time and Date conversion _ PHP Tutorial

Source: Internet
Author: User
Phpstrtotime () function Time and Date conversion. In php, the strtotime () function resolves the date and time descriptions of any English text into Unix timestamps. This function is also frequently used. if you need it, please refer to it. Syntax in php, the strtotime () function resolves the date and time descriptions of any English text into Unix timestamps. This function is also frequently used. For more information, see.

Syntax
Strtotime (time, now) parameter description
Time specifies the time string to be parsed.
Now is used to calculate the timestamp of the returned value. If this parameter is omitted, the current time is used.


Example

The code is as follows:

Echo strtotime ("now"), "n ";
Echo strtotime ("10 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 ";
?>


Example #2 failure check

The code is as follows:

$ Str = 'not Good ';

// Previous to PHP 5.1.0 you wowould 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 bug, just the way it works. But correct me if I'm wrong .)

$ Date = "06/10/2011"; // 6 October 2011 pm
$ OtherDate = ""; // 6 October 2011 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

?>


The Parse () function parses the datetime description of any English text into a Unix timestamp. This function is also frequently used. For more information, see. Syntax...

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.