search
Homephp教程php手册PHP关于时间计算的结总

PHP关于时间计算的结总

Jun 13, 2016 am 10:27 AM
phpaboutItimeTime differenceyesofcalculate


php中计算时间差有时候是件很麻烦的事!
不过我相信任何语言,只要撑握了其中规率就能找到办法,绝对是化腐朽为神奇的。
工作中经常要进行日期计算,下面总结几个工作中总结出的经验。先记下免得日后会忘!
1。第一种 计算时间段差(可以是分,秒,天)
$endtime="2004-09-09 18:10:00";$d1=substr($endtime,17,2); //秒$d2=substr($endtime,14,2); //分$d3=substr($endtime,11,2); // 时$d4=substr($endtime,8,2); //日$d5=substr($endtime,5,2); //月$d6=substr($endtime,0,4); //年
echo $d1.-.$d2.-.$d3.-.$d5.-.$d4.-.$d6."n";
echo date("Y-m-d H:i:s")."n";$now_T=mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y")); echo $now_T."n";$now_S=mktime("$d3","$d2","$d1","$d5","$d4","$d6");echo $now_S."n"; $end_TS=($now_S-$now_T)/60; //计算 剩余分钟echo $end_TS;?>
注 $startdate=mktime("0","0","0","1","1","2000"); //所得到的值为从1970-1-1到参数时间的总秒数 那么 化为分 /60 时 /3600 天/3600/24 即可!


若mktime()中的参数缺省,那表示使用当前日期。
2. 如果有数据库就很容易了!若是MSSQL可以使用触发器!用专门计算日期差的函数datediff()便可! 若是MYSQL那就用两个日期字段的差值计算的计算结果保存在另一个数值型字段中!用时调用便可!
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

MantisBT

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.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

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.