Home  >  Article  >  php教程  >  Commonly used time functions in php

Commonly used time functions in php

WBOY
WBOYOriginal
2016-10-22 11:56:211133browse

Test environment: php5.3.29

unix timestamp (number of seconds from the Unix epoch (January 1 1970 00:00:00 GMT) to a given time.). Hereinafter referred to as timestamp.


Returns the timestamp of a certain time.

time();

//Get the timestamp of the current local time.


mktime(hour, minute, second, month, day, year);

//It can be omitted from right to left, and the omitted parameters are replaced with the local time. For example, if the last day and year are omitted, the current time of 22nd 2016 will be used.

//You can write two or four digits for the year. When using two digits, 0-69 corresponds to 2000-2069, and 70-100 corresponds to 1970-2000. The four-digit time test is valid from 1970 to 2037.


date('Y-m-d H:i', $time);

//Get the timestamp of parameter 2 and obtain the string in the format of parameter 1. This is my most commonly used format: 2016-08-22 09:02

//Parameter 1 supports many letter values, such as: s (seconds with leading zeros), M (month with three-letter abbreviation), y (two-digit year), T (time zone where the machine is located) ) Wait and check in the manual.


getdate($timestamp);

//Return a unix timestamp as an array, the default value is the current local time, the return value format is as follows

Array
(
    [seconds] => 40
    [minutes] => 58
    [hours]   => 9//24小时制的9点
    [mday]    => 22//日期
    [wday]    => 6//礼拜6
    [mon]     => 10//十月
    [year]    => 2016
    [yday]    => 295//今年的第295天
    [weekday] => Saturday//礼拜6
    [month]   => October//十月
    [0]       => 1055901520//时间戳
)

Uh-huh. These are the ones I commonly use.

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