PHP中Date()时间日期函数的使用方法小结
PHP开发中Date()时间日期函数的使用方法php date() 函数可把时间戳格式化为可读性更好的日期和时间。
语法
date(format,timestamp)参数 描述
format 必需。规定时间戳的格式。
timestamp 可选。规定时间戳。默认是当前的日期和时间
要找出前一天的时间就是 time()-60*60*24;
要找出前一年的时间就是 time()*60*60*24*365
那么如何把这个数字换成日期格式呢 ,就要用到date()函数了
$t=time();www.3ppt.com
echo date("y-m-d h:i:s" ,$t);
每一个参数的格式分别表示:
a - "am" 或是 "pm"
a - "am" 或是 "pm"
d - 几日,二位数字,若不足二位则前面补零; 如: "01" 至 "31"
d - 星期几,三个英文字母; 如: "fri"
f - 月份,英文全名; 如: "january"
h - 12 小时制的小时; 如: "01" 至 "12"
h - 24 小时制的小时; 如: "00" 至 "23"
g - 12 小时制的小时,不足二位不补零; 如: "1" 至 12"
g - 24 小时制的小时,不足二位不补零; 如: "0" 至 "23"
i - 分钟; 如: "00" 至 "59"
j - 几日,二位数字,若不足二位不补零; 如: "1" 至 "31"
l - 星期几,英文全名; 如: "friday"
m - 月份,二位数字,若不足二位则在前面补零; 如: "01" 至 "12"
n - 月份,二位数字,若不足二位则不补零; 如: "1" 至 "12"
m - 月份,三个英文字母; 如: "jan"
s - 秒; 如: "00" 至 "59"
s - 字尾加英文序数,二个英文字母; 如: "th","nd"
t - 指定月份的天数; 如: "28" 至 "31"
u - 总秒数
w - 数字型的星期几,如: "0" (星期日) 至 "6" (星期六)
y - 年,四位数字; 如: "1999"
y - 年,二位数字; 如: "99"
z - 一年中的第几天; 如: "0" 至 "365"
其它不在上列的字符则直接列出该字符
php 日期 - 格式化日期
date() 函数的第一个参数规定了如何格式化日期/时间。它使用字母来表示日期和时间的格式。这里列出了一些可用的字母:
d - 月中的天 (01-31)
m - 当前月,以数字计 (01-12)
y - 当前的年(四位数)
您可以在我们的 php date 参考手册中,找到格式参数中可以使用的所有字母。
可以在字母之间插入其他字符,比如 "/"、"." 或者 "-",这样就可以增加附加格式了:
代码如下:
echo date("y/m/d");
echo "
";
echo date("y.m.d");
echo "
";
echo date("y-m-d");
?>

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

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

If you're looking for a way to automatically create and name files and folders based on system timestamps, you've come to the right place. There is a super simple way to accomplish this task. The created folders or files can then be used for various purposes such as storing file backups, sorting files based on date, etc. In this article, we will explain in some very simple steps how to automatically create files and folders in Windows 11/10 and name them according to the system’s timestamp. The method used is a batch script, which is very simple. Hope you enjoyed reading this article. Section 1: How to automatically create and name a folder based on the current timestamp of the system Step 1: First, navigate to the parent folder where you want to create the folder,

When developing using PHP programs, you often encounter some warning or error messages. Among them, one error message that may appear is: PHPWarning:date()expectsparameter2tobelong,stringgiven. The error message means: the second parameter of the function date() is expected to be a long integer (long), but what is actually passed to it is a string (string). So, we

1. Introduction The Date class in the java.util package represents a specific time, accurate to milliseconds. If we want to use our Date class, then we must introduce our Date class. Writing the year directly into the Date class will not produce the correct result. Because Date in Java is calculated from 1900, so as long as you fill in the first parameter with the number of years since 1900, you will get the year you want. The month needs to be subtracted by 1, and the day can be inserted directly. This method is rarely used, and the second method is commonly used. This method is to convert a string that conforms to a specific format, such as yyyy-MM-dd, into Date type data. First, define an object of Date type Date

There are many excellent calendar libraries and date libraries in Python for us to use. These libraries can help us handle date and calendar related operations. Next, I will introduce you to several common choices and provide corresponding code examples. Datetime library: Datetime is Python's built-in date and time processing module. It provides many date and time related classes and methods, which can be used to process dates, times, time differences and other operations. Sample code: importdatetime#Get the current date

How to get millisecond representation of date using getTime() method of Date class In Java, Date class is a class used to represent date and time. It provides many useful methods to manipulate and obtain information about date objects. Among them, the getTime() method is an important method in the Date class, which can return the millisecond representation of the date object. Next, we will detail how to use this method to obtain the millisecond representation of a date, and provide corresponding code examples. Using the Date class

I encountered a problem. After springboot was upgraded to 2.0, the date found from the database was received using Date and finally returned directly to the front end. It can be displayed normally in the yyyy-MM-ddHH:mm:ss format in Google Chrome. However, the date displayed in the IE browser is "garbled" because the springboot1.x version returns a timestamp in the Date field by default, and Google and IE will automatically convert the timestamp into yyyy-MM-ddHH:mm:ss ;After springboot2.0, spring will automatically convert the Date field into a UTC string (without configuration), so date needs to be converted into a timestamp or y

Stringbuild class Since the object content of the String class cannot be changed, a new String object will be constructed every time it is spliced, which is time-consuming and wastes memory space. At this time, you need to solve this problem through the StringBuild class provided by Java. StringBuilder is also called a variable character sequence. , it is a string buffer similar to String, which can be regarded as a container. Many strings can be held in the container. Variable means that the content in the StringBuilder object is variable. The construction method publicStringBuilder(): creates an empty buffer publicStringBuilder(Stringsr

The java.util package provides the Date class to encapsulate the current date and time. The Date class provides two constructors to instantiate Date objects. The first constructor initializes the object with the current date and time: Date() The second constructor receives a parameter, which is the number of milliseconds since January 1, 1970. After the Date object is created, you can call the following method: Serial number method description 1booleanafter(Datedate), if the Date object calling this method returns true after the specified date, otherwise it returns false2booleanbefore(Datedate), if
