1, get local timestamp
PHP uses the mktime() function to convert a time into a UNIX timestamp value. The timestamp is a long integer, including the UNIX era (January 1, 1070). Many times are based on this as the starting point. Interested friends can search for it. There must be stories in it.
The syntax format of the mktime() function is as follows:
int mktime(int time,int minute,int second,int month,int day,int year,int [is_dis])
The parameters of the mktime() function are explained in the following table:
2. Get the time and date
The current UNIX timestamp through the time() function in php. The syntax format is as follows:
int time(void)
The date() function in PHP is used to get the current time and date. The date() function format is as follows:
date(string format,int timestamp)
The date format functions are as shown in the following table:
getdate() function is mainly used to obtain relevant information in dates. The format of getdate() is as follows:
array getdate(int timestamp)
The returned array elements are as shown in the following table:
The specific sample code is as follows:
<code><span><span><?php </span><span>$array</span> = getdate(); <span>echo</span><span>$array</span>[<span>'year'</span>].<span>"-"</span>.<span>$array</span>[<span>'mon'</span>].<span>"-"</span>.<span>$array</span>[<span>'mday'</span>]; <span>?></span></span></span></code>
The running results are as follows:
3. Check the validity of the date
Checking the validity of the date is mainly implemented through the checkdate() function. The specific syntax is as follows:
bool checkdate(int month,int day,int year)
Let’s use code to implement it below:
<code><span><?php </span><span>$year</span> =<span>2011</span>; <span>$month</span> =<span>2</span>; <span>$day</span> =<span>31</span>; <span>echo</span> var_dump(checkdate(<span>$day</span>,<span>$month</span>,<span>$year</span>)); <span>?></span></span></code>
The running results are:
4, output the formatted time and date
This is mainly achieved through the date() function.
The format parameters are as follows:
5, first the localized time and date
The localization of time and date is mainly achieved through the setlocale() function.
The specific syntax is as follows:
string setlocale(string category,string locale)
The options for the parameter category are as shown in the following table:
If the parameter locale is empty, the locale or lang value of the system variable will be used, otherwise the localization environment specified by locale will be applied. For example, en_US is the localized environment of the United States, chs refers to Simplified Chinese, and cht refers to Traditional Chinese.
strftime() function
The strftime() function formats the output time and date according to the locale environment
The syntax format is as follows:
string strftime( string format, int timestamp)
The specific example code is as follows:
<code><span><?php </span>setlocale(LC_ALL,<span>"en_US"</span>); <span>echo</span><span>"美国格式:"</span>.strftime(<span>"Today is %A"</span>).<span>"\n"</span>; setlocale(LC_ALL,<span>"chs"</span>); <span>echo</span><span>"中文简体格式:"</span>.strftime(<span>"今天是:%A"</span>).<span>"\n"</span>; setlocale(LC_ALL,<span>"cht"</span>); <span>echo</span><span>"繁体中文格式:"</span>.strftime(<span>"今天是 :%A"</span>).<span>"\n"</span>; <span>?></span></span></code>
The running results are as follows:
6, parse the time and date into UNIX timestamp
It is mainly implemented through the strtotime() function.
int strtotime(string time,[,int time])
This function has two parameters. If time is an absolute time, the now parameter has no effect. If the format of the time parameter is relative time, then the corresponding time is provided by now. If now time is not provided, the corresponding time is the current time. Returns false if parsing fails.
The sample code is as follows:
<code><span><span><?php </span><span>echo</span> strtotime(<span>"now"</span>).<span>"\n"</span>; <span>//当前时间的时间戳</span><span>echo</span><span>"输出时间:"</span>.date(<span>"Y-m-d H:i:s"</span>,strtotime(<span>"now"</span>)).<span>"\n"</span>; <span>//按照格式要求输出当前的时间</span><span>echo</span> strtotime(<span>"21 May 2009"</span>).<span>"\n"</span>; <span>//输出指定时间的时间戳</span><span>echo</span><span>"输出时间:"</span>.date(<span>"Y-m-d H:i:s"</span>,strtotime(<span>"21 May 2009"</span>)).<span>"\n"</span>; <span>//按照格式输出指定时间的时间</span><span>echo</span> strtotime(<span>"+3 day"</span>).<span>"\n"</span>; <span>// 输出三天以后的时间戳</span><span>echo</span><span>"输出时间:"</span>.date(<span>"Y-m-d H:i:s"</span>,strtotime(<span>"+3 day"</span>)).<span>"\n"</span>; <span>//按照格式输出三天后的时间</span><span>echo</span> strtotime(<span>"+1 week"</span>).<span>"\n"</span>; <span>//输出一周以后的时间戳</span><span>echo</span><span>"输出时间:"</span>.date(<span>"Y-m-d H:i:s"</span>,strtotime(<span>"+1 week"</span>)).<span>"\n"</span>; <span>//按照格式输出一周以后的时间</span><span>echo</span> strtotime(<span>"+1 week 2 days 3 hours 4 minutes"</span>).<span>"\n"</span>; <span>echo</span> strtotime(<span>"next week"</span>).<span>"\n"</span>; <span>echo</span> strtotime(<span>"last Monday"</span>).<span>"\n"</span>; <span>?></span></span></span></code>
The running results are as follows:
The above introduces the time of PHP development, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.

Autoloading in PHP automatically loads class files when needed, improving performance by reducing memory use and enhancing code organization. Best practices include using PSR-4 and organizing code effectively.

PHP streams unify handling of resources like files, network sockets, and compression formats via a consistent API, abstracting complexity and enhancing code flexibility and efficiency.

The article discusses managing file upload sizes in PHP, focusing on the default limit of 2MB and how to increase it by modifying php.ini settings.

The article discusses nullable types in PHP, introduced in PHP 7.1, allowing variables or parameters to be either a specified type or null. It highlights benefits like improved readability, type safety, and explicit intent, and explains how to declar

The article discusses the differences between unset() and unlink() functions in programming, focusing on their purposes and use cases. Unset() removes variables from memory, while unlink() deletes files from the filesystem. Both are crucial for effec


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

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

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
