The way PHP converts dates into strings is: we can do it through the date() function. The date() function is used to format the local date and time. If successful, it will return the formatted date string. If it fails, it will report an E_WARNING error and return FALSE.
#To convert a date timestamp into a time string, you can use the date() function.
(Recommended tutorial: php tutorial)
Function introduction:
date() function is used to format local date and time and return the format ized date string.
Syntax
date(format,timestamp);
Returns the string generated by converting the integer timestamp according to the given format string. If no timestamp is given, the local current time is used. In other words, timestamp is optional and the default value is time().
Return value:
If successful, the formatted date string will be returned. If failed, an E_WARNING error will be reported and FALSE will be returned.
Code implementation:
$time_str = date('Y-m-d H:i:s', time()); // 将时间戳转化为相应的时间字符串 echo $time_str; // string(19) "2018-01-17 02:24:34" //反之 $time_int = strtotime($time_str); // 将时间字符串转化为时间戳 echo $time_int; // int(1516155874)
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
