Home > Backend Development > PHP Problem > How to convert string to date in php

How to convert string to date in php

王林
Release: 2023-03-04 09:58:01
Original
5390 people have browsed it

php method to convert a string into a date: You can use the strtotime() function to convert. The strtotime() function can parse any string datetime description into a Unix timestamp. Returns a timestamp on success, FALSE on failure.

How to convert string to date in php

strtotime() function parses any string datetime description into a Unix timestamp (number of seconds since January 1 1970 00:00:00 GMT ). Returns a timestamp on success, FALSE on failure.

(Recommended tutorial: php graphic tutorial)

Syntax:

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

Parameters:

  • time is required. Specifies a date/time string.

  • #now Optional. Specifies the timestamp used to calculate the return value. If this parameter is omitted, the current time is used.

(Video tutorial recommendation: php video tutorial)

Code implementation:

// 将指定日期转成时间戳,例如"20190813121721"
echo(strtotime(“20190813121721”));
// 将指定日期转成时间戳,例如"2019-08-13 12:17:21"
echo(strtotime(“2019-08-13 12:17:21”));
Copy after login

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

Related labels:
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