


Date and time functions are a core component of PHP. No installation is required to use these functions. Let’s talk about the specific usage of date function in detail:
PHP Date() Function
The PHP Date() function formats a timestamp into a more readable date and time.
Syntax
date(format,timestamp)
format required. Specifies the format of the timestamp.
timestamp optional. Specify timestamp. The default is the current date and time.
PHP’s date and time function date()
$t=time();
echo date("Y-m-d H:i:s",$t);
The format of the first parameter respectively represents:
a - "am" or "pm"
A - "AM" or "PM"
d - day, two digits, If there are less than two digits, add zeros in front; such as: "01" to "31"
D - day of the week, three English letters; such as: "Fri"
F - month, full English name; such as: " January"
h - hour in 12-hour format; such as: "01" to "12"
H - hour in 24-hour format; such as: "00" to "23"
g - 12-hour format For hours in 24-hour format, do not add zeros for less than two digits; for example: "1" to 12"
G - For hours in 24-hour format, do not add zeros for less than two digits; for example: "0" to "23"
i - Minutes; such as: "00" to "59"
j - day, two digits, if there are less than two digits, do not add zero; such as: "1" to "31"
l - day of the week, in full English name; such as: "Friday"
m - month, two digits, if less than two digits, add zeros in front; such as: "01" to "12"
n - month, two digits, if less than two digits If two digits are used, zeros will not be added; such as: "1" to "12"
M - month, three English letters; such as: "Jan"
s - seconds; such as: "00" to "59"S - add an English ordinal number at the end of the word, two English letters; such as: "th", "nd"
t - specify the number of days in the month; such as: "28" to "31"
U - total seconds Number
w - numeric day of the week, such as: "0" (Sunday) to "6" (Saturday)
Y - year, four digits; such as: "1999"
y - year, Two digits; such as: "99"
z - the day of the year; such as: "0" to "365"
Other characters not listed above will be listed directly
1, year-month-day
echo date('Y-m-j');2007-02-6
echo date('y-n-j');
07-2-6
Capital Y means four digits of the year numbers, 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
The uppercase M represents the 3 abbreviation characters of the month, while the lowercase m represents the number of the month (with leading 0);
There is no uppercase J, only the lowercase j represents the date of the month, without the leading o; if the month is required Use a lowercase d when leading.
echo date('Y-M-j' );
2007-Feb-6
echo date('Y-F-jS');
2007-February-6th
Capital M represents the three abbreviated characters of the month, while capital F represents the full English character 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.
Summary:
The year can be represented by uppercase Y and lowercase y;
The month can be represented by uppercase F, uppercase M, lowercase m and lowercase n (two ways to represent characters and numbers respectively) );
You can use lowercase d and lowercase j to represent the day, and uppercase S represents the suffix of the date.
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, it is necessary 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 the 24-hour system, but without a leader; use capital H to represent the hour in the 24-hour system with a leader
Summary:
The letter g represents the hour without a leader , the letter h represents the hour with a leading;
lowercase g and h represent the 12-hour format, and capital 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 means to determine whether this year is a leap year, Boolean value, returns 1 if true, otherwise 0;
Small l represents the full English version of the day of the week (Tuesday);
Use capital D to represent the day of the week The 3-character abbreviation of a few (Tue).
echo date('w');
Today’s week: 2
echo date('W');
This week is the 06th week of the year
The lowercase w represents the day of the week, expressed in numeric form
The uppercase W represents the number of weeks in the year
echo date('t');
This month is 28 days
echo date('z');
Today is the 36th day of this year
Lowercase t represents the number of days in the current month
Lowercase z represents the day of the year today
4, others
echo date('T');
UTC
Capital T indicates the server’s time zone setting
echo date('I');
0
Capital I means to determine whether the current daylight saving time is, if true, return 1, otherwise 0
echo date('U');
1170769424
The 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 the ISO8601 date. The date format is YYYY-MM-DD. The letter T is used to separate the date and time. The time format is HH:MM:SS. The time zone is represented by the offset from Greenwich Mean Time (GMT). .
echo date('r');
Tue, 06 Feb 2007 14:25:52 0000
Lowercase r represents the RFC822 date.

如果您正在寻找根据系统时间戳自动创建文件和文件夹并为其命名的方法,那么您来对地方了。有一种超级简单的方法可以用来完成这项任务。然后,创建的文件夹或文件可用于各种目的,例如存储文件备份、根据日期对文件进行排序等。在本文中,我们将通过一些非常简单的步骤解释如何在Windows11/10中自动创建文件和文件夹,并根据系统的时间戳对其进行命名。使用的方法是批处理脚本,非常简单。希望你喜欢阅读这篇文章。第1节:如何根据系统当前时间戳自动创建文件夹并命名第1步:首先,导航到要在其中创建文件夹的父文件夹,

在使用PHP程序开发时,经常会碰到一些警告或者错误的提示信息。其中,可能出现的一个错误提示就是:PHPWarning:date()expectsparameter2tobelong,stringgiven。这个错误的提示信息意思是:函数date()的第二个参数期望是长整型(long),但是实际传递给它的是字符串(string)。那么,我们

一.介绍java.util包中的Date类表示特定的时间,精确到毫秒。如果要想使用我们的Date类,那么我们必须得引入我们的Date类。Date类直接写入年份是得不到正确的结果的。因为java中Date是从1900年开始算的,所以前面的第一个参数只要填入从1900年后过了多少年就是你想要得到的年份。月需要减1,日可以直接插入。这种方法用的比较少,常用的是第二种方法。这种方法是将一个符合特定格式,比如yyyy-MM-dd,的字符串转化成为Date类型的数据。首先,定义一个Date类型的对象Date

Python中有许多优秀的日历库和日期库供我们使用,这些库可以帮助我们处理日期和日历相关的操作。接下来,我将为大家介绍几个常用的选择,并提供相应的代码示例。datetime库:datetime是Python内置的日期和时间处理模块,提供了许多日期和时间相关的类和方法,可以用于处理日期、时间、时间差等操作。示例代码:importdatetime#获取当

如何使用Date类的getTime()方法获取日期的毫秒表示形式在Java中,Date类是用于表示日期和时间的类。它提供了许多有用的方法来操作和获取日期对象的信息。其中,getTime()方法是Date类中的一个重要方法,它可以返回日期对象的毫秒表示形式。接下来,我们将详细介绍如何使用这个方法来获取日期的毫秒表示形式,并提供相应的代码示例。使用Date类的g

遇到一个问题,springboot升级成2.0后,从数据库查出来的日期,用Date接收,最后直接返回给前端,在谷歌浏览器中能正常显示成yyyy-MM-ddHH:mm:ss格式。但是在IE浏览器中日期显示的是“乱码”,因为springboot1.x版本的默认将Date字段返回的是时间戳,而谷歌、IE都会自动将时间戳转换成yyyy-MM-ddHH:mm:ss;在springboot2.0后,spring会将Date字段自动给转成UTC字符串了(在没有配置的情况下),所以date需要转换成时间戳还是y

Stringbuild类由于String类的对象内容不可改变,每次拼接都会构建一个新的String对象,既耗时,又浪费内存空间这时需要通过java提供的StringBuild类解决这个问题StringBuilder又称为可变字符序列,它是一个类似于String的字符串缓冲区,可以看作是一个容器,容器中可以装很多字符串可变指的是StringBuilder对象中的内容是可变的构造方法publicStringBuilder():创建一个空的缓冲区publicStringBuilder(Stringsr

java.util包提供了Date类来封装当前的日期和时间。Date类提供两个构造函数来实例化Date对象。第一个构造函数使用当前日期和时间来初始化对象:Date()第二个构造函数接收一个参数,该参数是从1970年1月1日起的毫秒数。Date(longmillisec)Date对象创建以后,可以调用下面的方法:序号方法描述1booleanafter(Datedate),若当调用此方法的Date对象在指定日期之后返回true,否则返回false2booleanbefore(Datedate),若当


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools
