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

How to convert date to string in php

王林
王林Original
2020-08-18 15:34:484399browse

How to convert date into string in php: You can use the date() function to achieve this. The date() function can format the timestamp into a more readable date and time. The usage method is: [echo date("Y/m/d")].

How to convert date to string in php

The PHP date() function formats a timestamp into a more readable date and time.

(Recommended tutorial: php graphic tutorial)

Syntax:

string date(string $format[, int $timestamp])

Parameters:

  • format Required. Specifies the format of the timestamp.

  • #timestamp Optional. Specify timestamp. The default is the current date and time.

(Video tutorial recommendation: php video tutorial)

Code implementation:

<?php
echo date("Y/m/d") . "<br>";
echo date("Y.m.d") . "<br>";
echo date("Y-m-d");
?>

Running result:

2020/10/21
2020.10.21
2020-10-21

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

Statement:
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