in the editor and click Enter to know the current date. time."/> in the editor and click Enter to know the current date. time.">

Home >Backend Development >PHP Problem >How to get the current date in php

How to get the current date in php

(*-*)浩
(*-*)浩Original
2019-10-16 14:51:228271browse

How to get the current date in php

1. Use the function date() to implement

Enter in the editor 6d7c905dc8801c17b89be18aa519cde2, click Enter to know the current time. Where Y represents the 4-digit year, H is the 24-hour format, and i is the minute, such as: "00" to "59". s - is the second, such as: "00" to "59" . (Recommended learning: PHP video tutorial)

d is the day, two digits, if there are less than two digits, add zero in front. Such as: "01" to "31". m represents the month, a two-digit number. If there are less than two digits, add zeros in front, such as: "01" to "12".

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 a day of the week

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

The following example formats today's date in three different ways:

Example

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

2. Use the time function

Input echo date("y-m-d",$time) in the editor and click Enter to know the current time, where Y represents the 4-digit year and m represents the month , a two-digit number, if there are less than two digits, add zeros in front, such as: "01" to "12". d is the day, a two-digit number. If there are less than two digits, zero will be added in front. Such as: "01" to "31".

3. Use strftime function

Enter echo strftime ("%hh%m %a %d %b", time()); click in the editor Press Enter to get the current time.

The above is the detailed content of How to get the current date 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