timer.class.php
//###################### Start Introduce #######################################
// author: bluemaple ; email: bluemaple@x263.net
// 最后修改时间2002-1-28 1:35
// 此函数求解决返回时间显示格式问题。包括date()函数的所有格式,默认的$type为最常用的类型
// 除了$year,$month,$day,$hour,$minute,$second;添加了$week(周),$zone(一年中的第几天),$numMonth(当前月份的天数)
// 其中默认的都为最常用的格式
// 特点,在时间处理中用得最多的是mktime,这里设置mktime可以按照习惯输入(年,月,日)显示
// mktimeY();mktimeW();mktimeM();mktimeD();可以方便设置一个时间相隔y年,n月,在mysql检索中方便使用
// subTime();函数可以方便求得两个时间相差的天数,周等
//####################### End Introduce ########################################
class TIMER{
var $year; // 年
var $month; // 月
var $day; // 日
var $hour; // 时
var $minute; // 分
var $second; // 秒
var $week; // 周
var $zone; // 一年中的第几天
var $numMonth; // 当前月份的天数
var $mktime; // mktime
function year($time="",$type=0){ // 返回年
// $type=0表示返回四位的年份
// $type=1表示返回二位的年份
if($time=="") $time=time();
if($type==0) $this->year=date("Y",$time);
if($type==1) $this->year=date("y",$time);
return $this->year;
}
function month($time="",$type=0){ // 返回月
// $type=0表示返回1~12
// $type=1表示返回01~12
// $type=2表示返回jan..三个英文字母
// $type=3表示返回英语全名
if($time=="") $time=time();
if($type==0) $this->month=date("n",$time);
if($type==1) $this->month=date("m",$time);
if($type==2) $this->month=date("M",$time);
if($type==3) $this->month=date("F",$time);
return $this->month;
}
function day($time="",$type=0){ // 返回日
// $type=0返回1~31
// $type=1返回01~31
if($time=="") $time=time();
if($type==0) $this->day=date("j",$time);
if($type==1) $this->day=date("d",$time);
return $this->day;
}
function hour($time="",$type=0){ // 返回时
// $type=0返回1~24
// $type=1返回1~12
// $type=2返回01~24
// $type=3返回01~12
if($time=="") $time=time();
if($type==0) $this->hour=date("H",$time);
if($type==1) $this->hour=date("h",$time);
if($type==2) $this->hour=date("G",$time);
if($type==3) $this->hour=date("g",$time);
return $this->hour;
}
function minute($time="",$type=0){ // 返回分
if($time=="") $time=time();
if($type==0) $this->minute=date("i",$time);
return $this->minute;
}
function second($time="",$type=0){ // 返回秒
// $type=0 返回1~59
// $type=1 返回字尾加英文序数,二个英文字母
if($time=="") $time=time();
if($type==0) $this->second=date("s",$time);
if($type==1) $this->second=date("S",$time);
return $this->second;
}
function week($time="",$type=0){ // 返回周
// $type=0 返回0~6
// $type=1 返回三个字母的周
// $type=2 返回全字母的周
if($time=="") $time=time();
if($type==0) $this->week=date("w",$time);
if($type==1) $this->week=date("D",$time);
if($type==2) $this->week=date("l",$time);
return $this->week;
}
function zone($time=""){ // 一年中的第几天;
if($time=="") $time=time();
$this->zone=date("z",$time);
return $this->zone;
}
function numMonth($time=""){ // 当前月的天数
if($time=="") $time=time();
$this->numMonth=date("t",$time);
return $this->numMonth;
}
function time($time=""){ //取得所有关于当前时间的参数。
if($time=="") $time=time();
$this->year($time);
$this->month($time);
$this->day($time);
$this->hour($time);
$this->minute($time);
$this->second($time);
$this->week($time);
$this->zone($time);
$this->numMonth($time);
}
function mktime($year=0,$month=0,$day=0,$hour=0,$minute=0,$second=0){ // 年月日时分秒
$this->mktime=mktime($hour,$minute,$second,$month,$day, $year);
return $this->mktime;
}
function mktimeY($time="",$y=1){ // 取得某一时间y年以前的,默认为1
$this->time($time);
$this->mktime=mktime(0,0,0,$this->month,$this->day,($this->year-$y));
return $this->mktime;
}
function mktimeM($time="",$m=1){ // 取得某一时间m月以前的,默认为1
$this->time($time);
$this->mktime=mktime(0,0,0,$this->month-$m,$this->day,$this->year);
return $this->mktime;
}
function mktimeD($time="",$d=1){ // 取得某一时间d天以前的,默认为1天
$this->time($time);
$this->mktime=mktime(0,0,0,$this->month,$this->day-$d,$this->year);
return $this->mktime;
}
function mktimeW($time="",$w=1){ // 取得某一时间w个周以前的,默认为1周
$this->time($time);
$this->mktime=mktime(0,0,0,$this->month,$this->day-7*$w,$this->year);
return $this->mktime;
}
function subTime($aTime="",$bTime=""){ // 两个时间之差,后者减去前者
if($aTime=="") $aTime = time();
if($bTime=="") $bTime = time();
$subTime = $bTime - $aTime;
$this->second=intval($subTime);
$this->minute=intval($subTime/60);
$this->hour=intval($this->minute/60);
$this->day=intval($this->hour/24);
$this->week=intval($this->day/7);
$this->month=intval($this->day/30);
$this->year=intval($this->monday/12);
}
}
?>
测试text.php
require("./timer.class.php");
//###################################
echo "
___________________________________
";
$TIMER=new TIMER;
$d=$TIMER->mktimeW();
$TIMER->subTime($d);
echo "second";echo $TIMER->second;echo "
";
echo "minute";echo $TIMER->minute;echo "
";
echo "hour";echo $TIMER->hour;echo "
";
echo "day";echo $TIMER->day;echo "
";
echo "week";echo $TIMER->week;echo "
";
echo "month";echo $TIMER->month;echo "
";
echo "year";echo $TIMER->year;echo "
";
echo "
___________________________________
";
?>

PHP和Python各有优势,选择应基于项目需求。1.PHP适合web开发,语法简单,执行效率高。2.Python适用于数据科学和机器学习,语法简洁,库丰富。

PHP不是在消亡,而是在不断适应和进化。1)PHP从1994年起经历多次版本迭代,适应新技术趋势。2)目前广泛应用于电子商务、内容管理系统等领域。3)PHP8引入JIT编译器等功能,提升性能和现代化。4)使用OPcache和遵循PSR-12标准可优化性能和代码质量。

PHP的未来将通过适应新技术趋势和引入创新特性来实现:1)适应云计算、容器化和微服务架构,支持Docker和Kubernetes;2)引入JIT编译器和枚举类型,提升性能和数据处理效率;3)持续优化性能和推广最佳实践。

在PHP中,trait适用于需要方法复用但不适合使用继承的情况。1)trait允许在类中复用方法,避免多重继承复杂性。2)使用trait时需注意方法冲突,可通过insteadof和as关键字解决。3)应避免过度使用trait,保持其单一职责,以优化性能和提高代码可维护性。

依赖注入容器(DIC)是一种管理和提供对象依赖关系的工具,用于PHP项目中。DIC的主要好处包括:1.解耦,使组件独立,代码易维护和测试;2.灵活性,易替换或修改依赖关系;3.可测试性,方便注入mock对象进行单元测试。

SplFixedArray在PHP中是一种固定大小的数组,适用于需要高性能和低内存使用量的场景。1)它在创建时需指定大小,避免动态调整带来的开销。2)基于C语言数组,直接操作内存,访问速度快。3)适合大规模数据处理和内存敏感环境,但需谨慎使用,因其大小固定。

PHP通过$\_FILES变量处理文件上传,确保安全性的方法包括:1.检查上传错误,2.验证文件类型和大小,3.防止文件覆盖,4.移动文件到永久存储位置。

JavaScript中处理空值可以使用NullCoalescingOperator(??)和NullCoalescingAssignmentOperator(??=)。1.??返回第一个非null或非undefined的操作数。2.??=将变量赋值为右操作数的值,但前提是该变量为null或undefined。这些操作符简化了代码逻辑,提高了可读性和性能。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

SublimeText3汉化版
中文版,非常好用

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。