PHP strtotime application experience_PHP tutorial
strtotime(date("Y-m-01 00:00:00")); // Used to get the timestamp of the first day of this month
In the actual PHP strtotime application, I suddenly encountered that the converted time was 8 hours slower than the actual time! I thought it was caused by the incorrect setting of
timezone in php.ini. After a round of inspection, I finally locked the problem on the strtotime function (problems often occur under Linux servers, and the data returned by the WINDOWS server is basically Correct)
Read the PHP manual carefully and found that the first parameter time has format requirements
time
The string to parse, according to the GNU » Date Input Formats syntax. Before PHP 5.0.0, microseconds weren't allowed in the time, since PHP 5.0.0 they are allowed but ignored.
Discovered through further follow-up on Date Input Formats
$ LC_ALL=C TZ=UTC0 date
Mon Mar 1 00:21:42 UTC 2004
$ TZ=UTC0 date +'%Y-%m-%d %H:% M:%SZ'
2004-03-01 00:21:42Z
$ date --iso-8601=ns | tr T ' ' # --iso-8601 is a GNU extension.
2004 -02-29 16:21:42,692722128-0800
$ date --rfc-2822 # a GNU extension
Sun, 29 Feb 2004 16:21:42 -0800
$ date +'% Y-%m-%d %H:%M:%S %z' # %z is a GNU extension.
2004-02-29 16:21:42 -0800
$ date +'@% s.%N' # %s and %N are GNU extensions.
@1078100502.692722128
Found that our commonly used format yyyy-mm-dd HH:ii:ss does not meet the requirements. After a rough look, I decided to use UTC0 format and then updated the above code to the following code
strtotime(date("Y-m-01 00:00:00")."Z"); // Used to get the number of this month One day timestamp
This problem is solved!
Summary of PHP strtotime application:
During the development process, we sometimes overlooked some details due to system support. As in this example, this problem will not occur under the WINDOWS platform, but the PHP strtotime application should still follow the specifications. to avoid such problems.

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
