search
HomeBackend DevelopmentPHP TutorialArrangement of parameters related to date() date function in PHP_PHP tutorial

Add
date_default_timezone_set(PRC) to the front of the page; /*Adjust the time to Beijing time, php5 defaults to Greenwich Mean Time*/
date ()
a: "am" or "pm"
A: "AM" or "PM"
d: Day, two digits, zero if missing; from "01" to "31"
D: Day of the week, 3 English letters, such as: "Fri"
F: month, full English name, such as: "January"
h: hour in 12-hour format, from "01" to "12"
H: Hours in 24-hour format, from "00" to "23"
g: Hours in 12-hour format, no zeros added; from "1" to "12"
G: Hours in 24-hour format, no zeros added Zero; from "0" to "23"
j: a few days, not zero if missing; from "1" to "31"
l: day of the week, full English name, such as: "Friday"
m: month, two digits, from "01" to "12"
n: month, two digits, no zero padding; from "1" to "12"
M: month, 3 English digits Letters; such as: "Jan"
s: seconds; from "00" to "59"
S: add an English ordinal number at the end of the word, two English letters, such as: "21th"
t: specify the month Number of days, from "28" to "31"
U: Total seconds
w: Numeric day of the week, from "0 (Sunday)" to "6 (Saturday)"
Y: Year , four digits
y: year, two digits
z: day of the year; from "1" to "366"
============ ================================================== ====
1, year-month-day
indicates the year with uppercase Y and lowercase y;
indicates the month with uppercase F, uppercase M, lowercase m and lowercase n (respectively representing characters and numbers);
can be used to represent the day with lowercase d or lowercase j, and uppercase S represents the suffix of the date.
echo date('Y-m-j');
2007-02-6
echo date('y-n-j');
07-2-6
Capital Y means the fourth day of the year digits, while lowercase y represents the two-digit number of the year;
lowercase m represents the number of the month (with a leading), while lowercase n represents the number of the month without the leading.
echo date('Y-M-j');
2007-Feb-6
echo date('Y-m-d');
2007-02-06
Capital M represents the month 3 abbreviation characters, and lowercase m represents the number of the month (with a leading 0);
There is no uppercase J, only a lowercase j represents the date of the month, without a leading o; if the month needs a leading, use a lowercase d.
echo date('Y-M-j');
2007-Feb-6
echo date('Y-F-jS');
2007-February-6th
Capital M represents the month 3 abbreviation characters, and capital F represents the full English version of the month. (No lowercase f)
Capital S represents the suffix of the date, such as "st", "nd", "rd" and "th", depending on the date number.
2, hours: minutes: seconds
By default, the time displayed by PHP interpretation is "Greenwich Mean Time", which is 8 hours different from our local time.
echo date('g:i:s a');
5:56:57 am
echo date('h:i:s A');
05:56:57 AM
A lowercase g indicates a 12-hour format without leading 0s, while a lowercase h indicates a 12-hour format with leading 0s.
When using the 12-hour clock, you need to indicate morning and afternoon. Lowercase a represents lowercase "am" and "pm", and uppercase A represents uppercase "AM" and "PM".
echo date('G:i:s');
14:02:26
Capital G represents the hour in 24-hour format, but without leading; use capital H to represent with leading 24-hour hour number
Summary:
The letter g represents the hour without a leading, the letter h represents the hour with a leading;
Lowercase g and h represent the 12-hour format, and uppercase G and H represent the 24-hour format.
3, leap year, week, day
echo date('L');
Whether this year is a leap year: 0
echo date('l');
Today is: Tuesday
echo date('D');
Today is: Tue
Capital L indicates whether this year is a leap year, Boolean value, returns 1 if true, otherwise 0;
Lowercase l indicates the day of the week in English Write in full (Tuesday);
and use a capital D to represent the 3-character abbreviation of the day of the week (Tue).
echo date('w');
Today's week: 2
echo date('W');
This week is the 06th week of the year
Lowercase w represents the day of the week , represented in numerical form
Capital W represents the number of weeks in the year
echo date('t');
This month has 28 days
echo date('z');
Today It is the 36th day of this year
Lowercase t indicates the number of days in the current month
Lowercase z indicates the day of the year today
4, others
echo date('T');
UTC
Capital T indicates the time zone setting of the server
echo date('I');
0
Capital I indicates whether it is daylight saving time, and returns 1 if true, otherwise 0
echo date('U');
1170769424
Uppercase U represents the total number of seconds from January 1, 1970 to the present, which is the UNIX timestamp of the Unix time epoch.
echo date('c');
2007-02-06T14:24:43+00:00
Lowercase c represents ISO8601 date, the date format is YYYY-MM-DD, separated by the letter T Date and time, the time format is HH:MM:SS, and the time zone is expressed using the offset from Greenwich Mean Time (GMT).
echo date('r');
Tue, 06 Feb 2007 14:25:52 +0000
Lowercase r represents the RFC822 date.
5. Format time
echo $row["t_time"]; will output 2008-2-29 12:08:00
echo date("Y-m-d",strtotime($row["t_time" ])); will output 2008-2-29
Note, since the time obtained by $row["t_time"] is already a string, you need to use strtotime (string to timestamp) to convert it, otherwise it will output 1970 -01-01 error

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323943.htmlTechArticleAdd date_default_timezone_set (PRC) to the front page of the page; /*Adjust the time to Beijing time, php5 defaults to Greenwich Mean Time*/ date () a: "am" or "pm" A: "AM" or "PM" d: Day...
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
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么查找字符串是第几位php怎么查找字符串是第几位Apr 22, 2022 pm 06:48 PM

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

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.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function