Conversion method: 1. Use strtotime() to convert the specified date and time into a timestamp, the syntax is "strtotime("specified date and time")"; 2. Use the date() function to format the timestamp and convert it Convert the time to "y m d" format, the syntax is "date("y m d", timestamp);".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php will change the date and time Converting to y m d format
can be converted into two steps:
-
Use strtotime() to convert the specified date and time into a timestamp
Use the date() function to format the timestamp and convert it to a time in the "y m d" format
Implementation code:
<?php header("content-type:text/html;charset=utf-8"); $str="2022-01-18"; $timestamp=strtotime($str); $time=date("y m d",$timestamp); echo "y m d格式的时间:".$time; ?>
date() function formats the local date and time and returns the formatted date string.
Syntax:
date(format,timestamp);
Parameters | Description |
---|---|
format | Required. Specifies the format of the output date string. The following characters are available:
Also, you can also use the following predefined constants (available starting from PHP 5.1.0):
|
timestamp | Optional. Specifies an integer Unix timestamp. The default is the current local time (time()). |
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert date and time to ymd format 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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
