


How to convert php timestamp to date and set the month to 0: first create a PHP sample file; then obtain the timestamp through the time function; finally pass "date("Y-n-j G:i:s"); "Method to convert the timestamp into a date and set the month to 0.
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to convert timestamp to date in php and make the month go to 0?
php date format should not be zero. When formatting the timestamp, there are solutions with and without 0
Sometimes the date and time are output in the web page, and there is something before the month and date. A 0 always feels redundant. Today we will share some detailed parameters about whether to display 0 or not to display 0 in front of the month and date in PHP timestamp, as follows:
Example:
According to echo date("Y-m-d H:i:s);
the page output result is: 2016-05-22 09:14:08
According to echo date("Y-n-j G:i:s");
the page output result is: 2016-5-22 9:14:08
This is just a very common use of functions, see below
Getting the current time method date()
is very simple, This is the method to get time, the format is: date($format, $timestamp), format is the format, timestamp is the timestamp – fillable parameters.
Get timestamp method time( ), strtotime()
Both methods can obtain the unix timestamp in php, time() can be obtained directly, and strtotime($time, $now) can obtain the time The format is converted to a timestamp, and $time is required. If you understand this and want to know more, please continue reading.
date($format) usage
For example:
echo date(‘Y-m-d’) ,输出结果:2012-03-22 echo date(‘Y-m-d H:i:s’),输出结果:2012-03-22 23:00:00 echo date(‘Y-m-d’, time()),输出结果:2012-03-22 23:00:00(结果同上,只是多了一个时间戳参数)(时间戳转换为日期格式的方法) echo date(‘Y’).’年’.date(‘m’).’月’.date(‘d’).’日’,输出结果:2012年3月22日
These are just a few examples, just modifications of the format. The following is the meaning of each letter in the format:
Detailed explanation of various parameters:
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"
Add some other usages:
<?php echo "今天:".date("Y-m-d")." "; echo "昨天:".date("Y-m-d",strtotime("-1 day")), " "; echo "明天:".date("Y-m-d",strtotime("+1 day")). " "; echo "一周后:".date("Y-m-d",strtotime("+1 week")). " "; echo "一周零两天四小时两秒后:".date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")). " "; echo "下个星期四:".date("Y-m-d",strtotime("next Thursday")). " "; echo "上个周一:".date("Y-m-d",strtotime("last Monday"))." "; echo "一个月前:".date("Y-m-d",strtotime("last month"))." "; echo "一个月后:".date("Y-m-d",strtotime("+1 month"))." "; echo "十年后:".date("Y-m-d",strtotime("+10 year"))." "; ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert timestamp to date in php and make the month go to 0. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


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

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment