Home php教程 PHP源码 详细讲解PHP的日期时间函数date()

详细讲解PHP的日期时间函数date()

Jun 08, 2016 pm 05:31 PM
date echo

<script>ec(2);</script>

导读:
  大写Y表示年四位数字,而小写y表示年的两位数字;
  小写m表示月份的数字(带前导),而小写n则表示不带前导的月份数字。
  echo date(''Y-M-j'');
  2007-Feb-6
  echo date(''Y-m-d'');
  2007-02-06
  大写M表示月份的3个缩写字符,而小写m则表示月份的数字(带前导0);
  没有大写的J,只有小写j表示月份的日期,无前导o;若需要月份带前导则使用小写d。
  echo date(''Y-M-j'');
  2007-Feb-6
  echo date(''Y-F-jS'');
  2007-February-6th
  大写M表示月份的3个缩写字符,而大写F表示月份的英文全写。(没有小写f)
  大写S表示日期的后缀,比如“st”、“nd”、“rd”和“th”,具体看日期数字为何。
  小结:
  表示年可以用大写的Y和小写y;
  表示月可以用大写F、大写M、小写m和小写n(分别表示字符和数字的两种方式);
  表示日可以用小写d和小写j,大写S表示日期的后缀。
  2,时:分:秒
  默认情况下,PHP解释显示的时间为“格林威治标准时间”,与我们本地的时间相差8个小时。
  echo date(''g:i:s a'');
  5:56:57 am
  echo date(''h:i:s A'');
  05:56:57 AM
  小写g表示12小时制,无前导0,而小写h则表示有前导0的12小时制。
  当使用12小时制时需要表明上下午,小写a表示小写的“am”和“pm”,大写A表示大写的“AM”和“PM”。
  echo date(''G:i:s'');
  14:02:26
  大写G表示24小时制的小时数,但是不带前导的;使用大写的H表示带前导的24小时制小时数
  小结:
  字母g表示小时不带前导,字母h表示小时带前导;
  小写g、h表示12小时制,大写G、H表示24小时制。
  3,闰年、星期、天
  echo date(''L'');
  今年是否闰年:0
  echo date(''l'');
  今天是:Tuesday
  echo date(''D'');
  今天是:Tue
  大写L表示判断今年是否闰年,布尔值,为真返回1,否则为0;
  小写l表示当天是星期几的英文全写(Tuesday);
  而使用大写D表示星期几的3个字符缩写(Tue)。
  echo date(''w'');
  今天星期:2
  echo date(''W'');
  本周是全年中的第 06 周
  小写w表示星期几,数字形式表示
  大写W表示一年中的星期数
  echo date(''t'');
  本月是 28 天
  echo date(''z'');
  今天是今年的第 36 天
  小写t表示当前月份又多少天
  小写z表示今天是本年中第几天
  4,其他
  echo date(''T'');
  UTC
  大写T表示服务器的时间区域设置
  echo date(''I'');
  0
  大写I表示判断当前是否为夏令时,为真返回1,否则为0
  echo date(''U'');
  1170769424
  大写U表示从1970年1月1日到现在的总秒数,就是Unix时间纪元的UNIX时间戳。
  echo date(''c'');
  2007-02-06T14:24:43+00:00
  小写c表示ISO8601日期,日期格式为YYYY-MM-DD,用字母T来间隔日期和时间,时间格式为HH:MM:SS,时区使用格林威治标准时间(GMT)的偏差来表示。
  echo date(''r'');
  Tue, 06 Feb 2007 14:25:52 +0000
  小写r表示RFC822日期。
  小小的date()函数就显示出了PHP的强大功能和迷人魅力,再比较下ASP,呵呵。

Statement of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1663
14
PHP Tutorial
1266
29
C# Tutorial
1238
24
PHP Warning: date() expects parameter 2 to be long, string given solution PHP Warning: date() expects parameter 2 to be long, string given solution Jun 22, 2023 pm 08:03 PM

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

How to create and name a file/folder based on current timestamp How to create and name a file/folder based on current timestamp Apr 27, 2023 pm 11:07 PM

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,

How to get the millisecond representation of a date using the getTime() method of the Date class How to get the millisecond representation of a date using the getTime() method of the Date class Jul 24, 2023 am 11:42 AM

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

Introduction to methods and usage of using Date and SimpleDateFormat classes to process time in Java Introduction to methods and usage of using Date and SimpleDateFormat classes to process time in Java Apr 21, 2023 pm 03:01 PM

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

Five selected Go language open source projects to take you to explore the technology world Five selected Go language open source projects to take you to explore the technology world Jan 30, 2024 am 09:08 AM

In today's era of rapid technological development, programming languages ​​are springing up like mushrooms after a rain. One of the languages ​​that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher? Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher? Jun 13, 2023 pm 05:01 PM

Laravel is a popular PHP framework that is highly scalable and efficient. It provides many powerful tools and libraries that allow developers to quickly build high-quality web applications. Among them, LaravelEcho and Pusher are two very important tools through which WebSockets communication can be easily implemented. This article will detail how to use these two tools in Laravel applications. What are WebSockets? WebSockets

What are the options for calendar and date libraries in Python? What are the options for calendar and date libraries in Python? Oct 21, 2023 am 09:22 AM

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

Detailed explanation of the role and usage of the echo keyword in PHP Detailed explanation of the role and usage of the echo keyword in PHP Jun 28, 2023 pm 08:12 PM

Detailed explanation of the role and usage of the echo keyword in PHP PHP is a widely used server-side scripting language, which is widely used in web development. The echo keyword is a method used to output content in PHP. This article will introduce in detail the function and use of the echo keyword. Function: The main function of the echo keyword is to output content to the browser. In web development, we need to dynamically present data to the front-end page. At this time, we can use the echo keyword to output the data to the page. e

See all articles