Home php教程 PHP源码 php 时间日期函数

php 时间日期函数

Jun 08, 2016 pm 05:28 PM
date int mktime quot

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

setlocale() mktime()
getdate 获得时间及日期信息。
语法: array getdate(int timestamp);
返回值: 数组
函数种类: 时间日期
内容说明 返回数组的元素包括下列的项目:
"seconds" - 秒
"minutes" - 分
"hours" - 时
"mday" - 当月的第几天
"wday" - 当周的第几天数字
"mon" - 月份数字
"year" - 年,数字
"yday" - 当年的第几天数字; 如: "299"
"weekday" - 星期几全名; 如: "Friday"
"month" - 月份全名; 如: "January"
gettimeofday 取得目前时间。
语法: array gettimeofday(void);
返回值: 数组
函数种类: 时间日期
内容说明 返回数组的元素包括下列的项目:
"sec" - 秒
"usec" - 百万分之一秒
"minuteswest" - 格林威治时间的分
"dsttime" - 目的的时区
gmdate 取得目前与 GMT 差后的时间。
语法: string gmdate(string format, int timestamp);
返回值: 字符串
函数种类: 时间日期
内容说明 本函数与 date() 函数相似,不同的是本函数返回与格林威治标准时间 (Greenwich Mean Time, GMT) 时间差后的时间
使用范例
echo date( "M d Y H:i:s",mktime(0,0,0,1,1,1998) );
echo gmdate( "M d Y H:i:s",mktime(0,0,0,1,1,1998) );
?>
若执行本范例的机器在芬兰 (Finland, GMT +0200),返回的结果为:
Jan 01 1998 00:00:00
Dec 31 1997 22:00:00
参考 date() mktime() gmmktime()
easter_date 计算复活节日期。
语法: int easter_date(int [year]);
返回值: 整数
函数种类: 时间日期
内容说明: 输入某一年份,则以 UNIX 时间戳记的格式返回该年的复活节日期,若没有输入年份,则计算当年的日期。值的?注意的是输入的年份必需在公元 1970 至 2037 年之间,否则无法计算。
使用范例

echo date("M-d-Y", easter_date(1999));
echo date("M-d-Y", easter_date(2000));
echo date("M-d-Y", easter_date(2001));
?>
返回结果为
Apr-04-1999
Apr-23-2000
Apr-15-2001
easter_days 计算复活节与三月廿一日之间日期数。
语法: int easter_days(int [year]);
返回值: 整数
函数种类: 时间日期
内容说明 输入某一年份,则以计算该年复活节与三月二十一日之间的日期数,若没有输入年份,则以当年计算。这个函数可以用来替代 easter_date() 1970-2037 年外范围无法计算的问题。
使用范例

echo easter_days(1999);
echo easter_days(1492);
echo easter_days(1913);
?>
返回结果为:
14 (4/4)
32 (4/22)
2 (3/23)
参考 easter_date()
mktime 取得 UNIX 时间戳记。
语法: int mktime(int hour, int minute, int second, int month, int day, int year);
返回值: 整数
函数种类: 时间日期
内容说明: 输入一个时间,则返回 UNIX 时间戳记的长整数。
使用范例

echo date( "M-d-Y", mktime(0,0,0,12,32,1997) );
echo date( "M-d-Y", mktime(0,0,0,13,1,1997) );
echo date( "M-d-Y", mktime(0,0,0,1,1,1998) );
?>
参考 date() time()
gmmktime 取得 UNIX 时间戳记的格林威治时间。
语法: int gmmktime(int hour, int minute, int second, int month, int day, int year);
返回值: 整数
函数种类: 时间日期
内容说明: 输入一个时间,则返回 UNIX 的格林威治时间戳记的长整数。
time 取得目前时间的 UNIX 时间戳记。
语法: int time(void);
返回值: 整数
函数种类: 时间日期
内容说明 返回目前时间的戳记值。
参考 date()
microtime 取得目前时间的 UNIX 时间戳记的百万分之一秒值。
语法: string microtime(void);
返回值: 字符串
函数种类: 时间日期
内容说明 返回目前时间的百万分之一秒戳记值。若操作系统没有提供 gettimeofday() 的系统呼叫函数,则本函数亦无效。

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

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)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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)

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,

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

Detailed explanation of the method of converting int type to bytes in PHP Detailed explanation of the method of converting int type to bytes in PHP Mar 06, 2024 pm 06:18 PM

Detailed explanation of the method of converting int type to byte in PHP In PHP, we often need to convert the integer type (int) to the byte (Byte) type, such as when dealing with network data transmission, file processing, or encryption algorithms. This article will introduce in detail how to convert the int type to the byte type and provide specific code examples. 1. The relationship between int type and byte In the computer field, the basic data type int represents an integer, while byte (Byte) is a computer storage unit, usually 8-bit binary data

C++ program to convert double type variable to int type C++ program to convert double type variable to int type Aug 25, 2023 pm 08:25 PM

In C++, variables of type int can only hold positive or negative integer values; they cannot hold decimal values. There are float and double values ​​available for this purpose. The double data type was created to store decimals up to seven digits after the decimal point. Conversion of an integer to a double data type can be done automatically by the compiler (called an "implicit" conversion), or it can be explicitly requested by the programmer from the compiler (called an "explicit" conversion). In the following sections, we'll cover various conversion methods. Implicit conversions The compiler performs implicit type conversions automatically. To achieve this, two variables are required - one of floating point type and the other of integer type. When we simply assign a floating point value or variable to an integer variable, the compiler takes care of all the other things

What is the value range of int32? What is the value range of int32? Aug 11, 2023 pm 02:53 PM

The value range of int32 is from -2 to the 31st power to 2 to the 31st power minus 1, that is, -2147483648 to 2147483647. int32 is a signed integer type, which means it can represent positive numbers, negative numbers, and zero. It uses 1 bit to represent the sign bit, and the remaining 31 bits are used to represent the numerical value. Since one bit is used to represent the sign bit, the effective number of int32 bits is 31.

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

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

How many bytes does int occupy? How many bytes does int occupy? Jan 22, 2024 pm 03:14 PM

The number of bytes occupied by the int type may vary in different programming languages ​​and different hardware platforms. Detailed introduction: 1. In C language, the int type usually occupies 2 bytes or 4 bytes. In 32-bit systems, the int type occupies 4 bytes, while in 16-bit systems, the int type occupies 2 bytes. In a 64-bit system, the int type may occupy 8 bytes; 2. In Java, the int type usually occupies 4 bytes, while in Python, the int type has no byte limit and can be automatically adjusted, etc.

See all articles