PHP中时间加减函数strtotime用法分析
2017-04-26 10:35
831 查看
时间加减
<?php //获取本地 提取年份+1 $date=date("Y-m-d",mktime(0,0,0,date("m") ,date("d"),date("Y")+1)); ?>
如果要获取数据库中的时间应该如何处理呢?在PHP文档中找到了一个很好的函数strtotime,可以对时间进行加减:
int strtotime ( string time [, int now] )
返回类型 int
函数可用于时间转换和加减。
<?php //date()格式化时间返回String类型。 //加一年 $date_year = date('Y-m-d',strtotime("$date + 1 year")); echo $date_year; //加一天 $date_tomorrow = date('Y-m-d',strtotime("2009-05-26 + 1 day")); echo $date_tomorrow; //加一周 $date_week = date('Y-m-d',strtotime("$date + 1 week")); echo $date_week; ?>
PS:这里再为大家推荐几款时间及日期相关工具供大家参考使用:
在线日期/天数计算器:
http://tools.jb51.net/jisuanqi/date_jisuanqi
在线日期计算器/相差天数计算器:
http://tools.jb51.net/jisuanqi/datecalc
在线日期天数差计算器:
http://tools.jb51.net/jisuanqi/onlinedatejsq
Unix时间戳(timestamp)转换工具:
http://tools.jb51.net/code/unixtime
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php日期与时间用法总结》、《PHP数组(Array)操作技巧大全》、《PHP基本语法入门教程》、《PHP运算与运算符用法总结》、《php面向对象程序设计入门教程》、《PHP网络编程技巧总结》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
您可能感兴趣的文章:
- PHP实现针对日期,月数,天数,周数,小时,分,秒等的加减运算示例【基于strtotime】
- PHP使用strtotime获取上个月、下个月、本月的日期
- PHP使用strtotime计算两个给定日期之间天数的方法
- php使用date和strtotime函数输出指定日期的方法
- PHP下获取上个月、下个月、本月的日期(strtotime,date)
- php使用strtotime和date函数判断日期是否有效代码分享
- PHP时间戳 strtotime()使用方法和技巧
- php 深入理解strtotime函数的使用详解
- PHP中strtotime函数使用方法详解
- PHP strtotime函数详解
- PHP正则匹配日期和时间(时间戳转换)的实例代码
- php 时间time与日期date之间的使用详解及区别
- 非常全面的php日期时间运算汇总
相关文章推荐
- php时间函数用法分析
- php strtotime 时间加减函数
- PHP strtotime函数用法、实现原理和源码分析
- PHP strtotime函数用法、实现原理和源码分析
- PHP的时间加减的函数strtotime
- PHP的时间加减的函数strtotime
- php时间函数用法分析
- php strtotime()函数对时间 加减的妙用 (实例)
- php中rename函数用法分析
- php strtotime 函数UNIX时间戳
- php字符比较函数similar_text、strnatcmp与strcasecmp用法分析
- PHP 日期转换为时间戳 strtotime 与 mktime 函数
- php&nbsp;strtotime函数和date函数用法
- php判断类是否存在函数class_exists用法分析
- php字符比较函数similar_text、strnatcmp与strcasecmp用法分析
- php中filter_input函数用法分析
- PHP的时间函数strtotime
- PHP 日期转换为时间戳 strtotime 与 mktime 函数
- php的strtotime函数源码分析