php method to determine whether two timestamps are one day: 1. Create a php sample file; 2. Set "int time_zone = 8, daily_reset_time = 5;"; 3. Pass "bool IsTimeToReset(time_t last_reset_time, time_t cur_time){...}" method can be used to determine.
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
How does PHP determine whether two timestamps are the same day?
To determine whether two timestamps are on the same day
Idea analysis
To determine whether two timestamps are not on the same day, just Divide the absolute seconds of each of the two days by 24 * 3600 to get how many days have passed from epoch to now. If the difference between the two results is greater than 0, it indicates that they are not the same day and need to be reset. But two factors need to be considered:
First, the current time minus the set reset time point (such as 5 o'clock every day), because it is reset at 5 o'clock, subtract 5*3600 to ensure the current The time is greater than or equal to the reset time point, which is 5 o'clock on the day.
The second is the absolute seconds plus the part of the timestamp corresponding to the corresponding time zone, so that the time obtained corresponds to the local time. For example, without adding a time zone, you get the number of days since 00:00:00 Greenwich Mean Time on January 1, 1970. Beijing time is 8 hours ahead of Greenwich Mean Time. Then if it is Greenwich Mean Time 16 o'clock in the U.S. time corresponds to zero o'clock on the next day in Beijing time. What we need to calculate in terms of time is the difference in days corresponding to the time in this time zone, so we need to add the time zone. The resulting time is time_zone * 3600
Code implementation
int time_zone = 8, daily_reset_time = 5; time_t BetweenDays(time_t time1, time_t time2) { return (time1 + time_zone *3600)/3600/24 - (time2 + time_zone *3600)/3600/24; } /* * last_reset_time 为上次执行的每日重置时间 * cur_time 为当前时间 */ bool IsTimeToReset(time_t last_reset_time, time_t cur_time) { return BetweenDays(cur_time - 3600 * daily_reset_time, last_reset_time - 3600 * daily_reset_time) > 0; }
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to determine whether two timestamps are the same day in php. 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

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

Hot Article

Hot Tools

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.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft