This article mainly introduces the detailed usage of the php strftime function. The strftime() function formats the local time/date according to the regional settings. Generally, it can be used for time formatting. Friends who need it can refer to it
Definition and Usage
strftime() function formats local time/date according to locale settings.
Syntax
strftime(format,timestamp) Parameter Description
format is optional. Specifies how results are returned.
timestamp Optional.
Tips and Notes
Tip: Same behavior as gmstrftime(), except that the returned time is local time.
Example
Output the results of strftime() and gmstrftime():
<?php教程 echo(strftime("%b %d %Y %X", mktime(20,0,0,12,31,98))); echo(gmstrftime("%b %d %Y %X", mktime(20,0,0,12,31,98))); //输出当前日期、时间和时区 echo(gmstrftime("It is %a on %b %d, %Y, %X time zone: %Z",time())); ?>
strftime The () function can convert date strings in the YYYY-MM-DD HH:MM:SS format into other forms of strings.
The syntax of strftime() is strftime(format, date/time, modifier, modifier, ...)
It can format dates and times with the following symbols:
%a | Abbreviation of the day of the week in the current area | Sun to Sat |
The full name of the day of the week in the current area | Sunday to Saturday | |
The day of the month, decimal number (range from 01 to 31) | 01 to 31 | |
The day of the month, decimal number, a digit will be added before Spaces (ranging from '1' to '31') are not implemented as described on Windows. More information below. | 1 to 31 | |
The day of the year as a three-digit decimal number with leading zeros (range 001 to 366) | 001 to 366 | |
Conforms to the ISO-8601 decimal representation of the day of the week [1,7], 1 represents Monday | 1 (Monday) to 7 (Sunday) | |
The day of the week, Sunday is 0 | 0 (Sunday) to 6 (Saturday) | |
--- | --- | |
The first week of the year, starting from the first Sunday of the first week as the first day | 13 (for the 13th full week of the year) | |
%V - ISO-8601:1988 format of the week of the year, ranging from 01 to 53, week 1 is the first of the year There are at least 4 days in the week, with Monday as the first day of the week. (Use %G or %g as the year composition of the corresponding week number of the specified timestamp.) | 01 to 53 (where 53 accounts for an overlapping week) | |
The week number of the year, starting from the first Monday of the first week as the first day | 46 (for the 46th week of the year beginning with a Monday) | |
--- | --- | |
The abbreviation of the current regional month | Jan to Dec | |
The full name of the current regional month | January to December | |
Abbreviation of the month in the current region (alias of %b) | Jan to Dec | |
Two-digit month | 01 (is January) to 12 (is December) | |
--- | --- | |
Two digits display the century (year divided by 100, truncated to integers) | 19 is the 20th century | ##%g |
For example: the week of January 6, 2009 is 09. | ||
%G | The complete four-digit version of %g | For example: the week of January 3, 2009 is 2008. |
%y | Two-digit display year | For example: 09 is 2009, 79 is 1979 |
Four-digit display year | For example: 2038 | |
--- | -- - | |
Display two-digit hours in 24-hour format | 00 to 23 | |
Display two-digit hours in 12-hour format | 01 to 12 | |
Display hours in 12-hour format, single digits with spaces before them | 1 to 12 | |
Two-digit minutes Numbers | 00 to 59 | |
Specify the uppercase "AM" or "PM" of the time | For example: 00 :31 is AM, 22:23 is PM | |
The lowercase "am" or "pm" of the specified time | For example: 00 :31 is am, 22:23 is pm | |
is the same as "%I:%M:%S %p" | For example: 21:34:17 is 09:34:17 PM | |
is the same as "%H:%M" | For example : 12:35 AM is 00:35, 4:44 PM is 16:44 | |
two digits represent seconds | 00 To 59 | |
is the same as "%H:%M:%S" | For example: 09:34:17 PM is 21 :34:17 | |
The preferred time representation in the current region, excluding the date | For example: 03:59:16 or 15: 59:16 | |
Time zone offset or abbreviation from UTC (determined by the operating system) | For example: Eastern Time is -0500 or EST | |
%z No time zone offset or abbreviation for UTC given (determined by the operating system) | For example: - 0500 or EST is Eastern Time | |
--- | --- | |
The preferred date and time expression in the current region | For example: February 5, 2009 12:45:10 am is Tue Feb 5 00:45:10 2009 | |
Same as "%m/%d/%y" | For example: February 5, 2009 is 02/05/09 | |
Same as "%Y-%m-%d" (commonly used in database datestamps) | For example: February 5, 2009 is 2009-02-05 | ##%s |
For example: September 1979 8:40:00 AM on the 10th is 305815200 | %x | |
. For example: 2009 February 5th is 02/05/09 | Other | |
--- | %n | |
--- | %t | |
--- | %% | |
The above is the detailed content of How to use strftime function in php. For more information, please follow other related articles on the PHP Chinese website!

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.

Autoloading in PHP automatically loads class files when needed, improving performance by reducing memory use and enhancing code organization. Best practices include using PSR-4 and organizing code effectively.

PHP streams unify handling of resources like files, network sockets, and compression formats via a consistent API, abstracting complexity and enhancing code flexibility and efficiency.

The article discusses managing file upload sizes in PHP, focusing on the default limit of 2MB and how to increase it by modifying php.ini settings.

The article discusses nullable types in PHP, introduced in PHP 7.1, allowing variables or parameters to be either a specified type or null. It highlights benefits like improved readability, type safety, and explicit intent, and explains how to declar

The article discusses the differences between unset() and unlink() functions in programming, focusing on their purposes and use cases. Unset() removes variables from memory, while unlink() deletes files from the filesystem. Both are crucial for effec


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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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

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
