Home > Backend Development > PHP Problem > How to use date to remove hours, minutes and seconds in php

How to use date to remove hours, minutes and seconds in php

醉折花枝作酒筹
Release: 2023-03-09 12:04:01
Original
3122 people have browsed it

In PHP, you can use the "date('Y-m-d',strtotime(date))" statement to remove hours, minutes and seconds. The date() function is used to format a date or time and format the timestamp into a more readable date and time.

How to use date to remove hours, minutes and seconds in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php time removes hours and minutes Seconds

<?php date(&#39;Y-m-d&#39;,strtotime(日期)) ?>
Copy after login

Related introduction:

The date() function in PHP is used to format date or time.

PHP Date() function formats a timestamp into a more readable date and time. date(format,timestamp)

Parameter description

format is required. Specifies the format of the timestamp.

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

Note: A timestamp is a sequence of characters that represents the date and event when a specific event occurred.

Get a simple date

The format parameters of the date() function are required, and they specify how to format the date or time.

Here are some characters commonly used for dates:

  • d - represents the day of the month (01-31)

  • m - represents the month (01-12)

  • Y - represents the year (four digits)

  • 1 - represents the week

Other characters, such as "/", "." or "-" can also be inserted into the characters to add other formatting.

The following example uses three different methods to format today's date:

Example

<?php
echo "今天是 " . date("Y/m/d") . "";
echo "今天是 " . date("Y.m.d") . "";
echo "今天是 " . date("Y-m-d") . "";
?>
Copy after login

Recommendation: "2021 PHP interview questions summary ( Collection)》《php video tutorial

The above is the detailed content of How to use date to remove hours, minutes and seconds in php. For more information, please follow other related articles on the PHP Chinese website!

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