How to convert date to string in php

王林
Release: 2023-03-04 17:50:01
Original
4349 people have browsed it

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])
Copy after login

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");
?>
Copy after login

Running result:

2020/10/21
2020.10.21
2020-10-21
Copy after login

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!

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