Home > Backend Development > PHP Problem > How to convert php string to time

How to convert php string to time

藏色散人
Release: 2023-03-08 11:32:02
Original
2714 people have browsed it

How to convert PHP string into time: first create a PHP sample file; then define a variable "$temp_date"; finally pass "date('Y-m-d',strtotime($temp_date));" Just convert the string variable into time.

How to convert php string to time

#The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

php string formatting into time

In normal times we often need to format the time of a string before using it

Php can use the following method:

$temp_date = '2011-01-09 19:25:43';
date('Y-m-d',strtotime($temp_date)); //这个的输出是 2011-01-09
Copy after login

The function of strtotime is-- Parse the date and time description of any English text into a UNIX timestamp

The following is the official description:

int strtotime ( string time [, int now])
Copy after login

This function is expected to accept a string containing an English date format and try to parse it into a UNIX timestamp. If the format of time is absolute time, the now parameter has no effect.

If the format of time is a relative time, the relative time is provided by now, or the current time is used if the now parameter is not provided. Returns -1 on failure.

The programs must be relatively robust, then we can judge whether they can be converted.

It should also be noted that this has a time interval: Friday, December 13, 1901 at 20:45 :54 Until Tuesday, January 19, 2038 03:14:07

[Recommended learning: "PHP Video Tutorial"]

The above is the detailed content of How to convert php string to time. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template