A bunch of date and time operations in php
Format date and time
date : Format Date and time
Scenario
Format the current date and time or a specific date and time ##The output is a string in a specific format, often used for humanized display of information.
Description
Remarks
Description | Return value example | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Y
|
4 Complete year with digits
|
2019
|
||||||||||||||||||||
| 2 Year represented by digits
| 19
|
||||||||||||||||||||
Three-letter abbreviation for the month |
Jan to Dec |
| ##m||||||||||||||||||||
The month represented by the number, with leading zeros
| 01 to 12
# #D |
|||||||||||||||||||||
3 letters
|
Mon to Sun
|
d |
||||||||||||||||||||
2 digits with leading zeros
|
01 to 31
|
H |
||||||||||||||||||||
24 hour format, with leading zeros
|
00 to 23
|
h |
||||||||||||||||||||
12 hour format, with leading zeros
|
01 to 12
|
I |
||||||||||||||||||||
If so Daylight saving time is 1 | , otherwise it is 0 |
##i
|
||||||||||||||||||||
00 to 59 |
S |
|||||||||||||||||||||
characters
| st,nd,rd or th , can be used together with | j
s
|
||||||||||||||||||||
00 to 59 |
## |
Description | Parameter example | |
---|---|---|
| hour Number of hours
| 00 to 23
|
minute | Minutes 00 to 59 |
| ##s
second Number of seconds | 00 to 59 | # #n |
month Number of months | 01 to 12
| ## j |
Number of days
| 01 to 31
| ##Y
|
0-69 | corresponds to 2000-2069 , 70-100 | corresponds to 1970-2000
|
The above is the detailed content of A bunch of date and time operations 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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



When writing programs in PHP, we often need to convert dates to timestamps, or timestamps to dates. This process is very simple in PHP and can be easily accomplished using just a few simple functions. In this article, we'll cover how to convert a PHP date to a timestamp, while also discussing some common usage scenarios.

Calculating date differences is very common in practical applications. For example, when doing website development, we may need to calculate the difference between two dates in order to correctly display timestamps, countdowns, etc. When calculating the date difference, we often need to calculate the month difference between two dates. Let's introduce how to use PHP to calculate the month difference between dates.

Judgment method: 1. Use the "strtotime("year-month-day")" statement to convert the given year, month and day into timestamp format; 2. Use the "date("z", timestamp)+1" statement to calculate Specifies the day of the year when the timestamp is specified. The number of days returned by date() is calculated from 0, so the real number of days needs to be added to this basis by 1.

In PHP, you can use the date() function to get the current date and day of the week. Just omit the second parameter of the date() function and set the first parameter to "Y-m-d H:i:s" to get the current date, the syntax is "date("Y-m-d H:i:s")"; and When the first parameter is set to "N", the day of the week can be obtained with the syntax "date("N")". "N" returns the day of the week as a number in ISO-8601 format, ranging from 1 (for Monday) to 7 (for Sunday).

PHP is a popular programming language that is widely used in web development. Converting between strings and dates is a very common operation in PHP. In this article, we will discuss how to convert PHP string to time format.

In PHP, you can use the date() function to convert seconds into hours, minutes and seconds format, with the syntax "date("H:i:s", timestamp)". The timestamp is the number of seconds since the Unix epoch to the current time, and the date() function can format the timestamp and convert the timestamp into a date string in a specified format through the format character set in the first parameter. The format character "H" represents the 24-hour format, and the "h" character can also be used, which represents the 12-hour format; the format character "i" represents the minutes value with leading zeros, and the format character "s" represents the seconds value with leading zeros.

In PHP, you can use the date() function to convert a timestamp into a date time. This function can format the timestamp into a more readable date and time; the syntax format is "date(format, timestamp)", The format parameter is used to specify the formatting character and set the date format to be converted, such as "Y-m-d H:i:s", which converts the timestamp into the "year-month-day hour:minute:second" format.

Two ways to add: 1. Directly use the strtotime() function to calculate the time interval, and the date after the interval can be returned in UNIX timestamp format, with the syntax "strtotime("+1 day")"; 2. Use the time() function Calculate the current timestamp and add the number of seconds in a day to the current timestamp. The syntax is "time()+(1 * 24 * 3600)".
