`
moqiang02
  • 浏览: 527073 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
文章分类
社区版块
存档分类
最新评论

PHP的时间函数strtotime

 
阅读更多
时间加减
  1. <?php
  2. //获取本地提取年份+1
  3. $date=date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")+1));
  4. ?>
如果要获取数据库中的时间应该如何处理呢?在PHP文档中找到了一个很好的函数strtotime,可以对时间进行加减:
  1. intstrtotime(stringtime[,intnow]) 
返回类型 int
函数可用于时间转换和加减。
  1. <?php
  2. //date()格式化时间返回String类型。
  3. //加一年
  4. $date_year=date('Y-m-d',strtotime("$date+1year"));
  5. echo$date_year;
  6. //加一天
  7. $date_tomorrow=date('Y-m-d',strtotime("2009-05-26+1day"));
  8. echo$date_tomorrow;
  9. //加一周
  10. $date_week=date('Y-m-d',strtotime("$date+1week"));
  11. echo$date_week;
  12. ?>

$time = strtotime('2014-06-10 00:06:00');
var_dump($time); //int 1402358760


分享到:
评论

相关推荐

    PHP中strtotime函数使用方法详解

    在PHP中有个叫做strtotime的函数。strtotime 实现功能:获取某个日期的时间戳,或获取某个时间的时间戳。strtotime 将任何英文文本的日期时间描述解析为Unix时间戳[将系统时间转化成unix时间戳] 一,获取指定日期的...

    PHP中时间加减函数strtotime用法分析

    本文实例讲述了PHP中时间加减函数strtotime用法。分享给大家供大家参考,具体如下: 时间加减 &lt;?php //获取本地 提取年份+1 $date=date("Y-m-d",mktime(0,0,0,date("m") ,date("d"),date("Y")+1)); ?&gt; 如果...

    php强大的时间转换函数strtotime

    使用strtotime可以将各种格式的时间字符串转换为时间戳 转换常规时间格式 echo date('Y-m-d H:i:s', strtotime('2016-01-30 18:00')).PHP_EOL; echo date('Y-m-d H:i:s', strtotime('20160130180001')).PHP_EOL; ...

    php使用date和strtotime函数输出指定日期的方法

    本文实例讲述了php使用date和strtotime函数输出指定日期的方法。分享给大家供大家参考。具体方法分析如下: 在php中date和strtotime函数都是对日期操作的,但是在生成上面date和strtotime是不一样的,一个是数字日期...

    PHP中strtotime函数使用方法.docx

    PHP中strtotime函数使用方法.docx

    Javascript模仿php中strtotime()函数实现时间字符串转时间戳方法

    document.write(strtotime('now')); document.write(strtotime('next Sunday')); document.write(strtotime('last month')); document.write(strtotime('+1 weeks')); document.write(strtotime('+1 WEEK')); ...

    php中strtotime函数性能分析

    strtotime()是php中的时间函数;其功能是:将任何字符串形式的日期,时间转换成对应的Unix 时间戳。今天我们是通过具体的实例来详细分析下strtotime()函数的性能问题

    PHP strtotime函数详解

    strtotime函数是一个很好的函数,灵活的运用它,会给你的工作带来不少方便.但PHP的手册中却对此函数的参数没作太多介绍,对些函数的其他介绍也非常少。

    PHP时间戳 strtotime()使用方法和技巧

    在php中我想要获取时间戳有多种方法,最常用的就是使用time函数与strtotime()函数把日期转换成时间戳了,下面我来给大家分享一下时间戳函数 strtotime用法。获取指定的年月日转化为时间戳:pHP时间戳函数获取指定...

    php中strtotime函数用法详解

    主要介绍了php中strtotime函数的用法,以实例形式详细分析了strtotime函数的参数含义与相应的用法,适用于时间格式变换的情况,需要的朋友可以参考下

    php 深入理解strtotime函数的使用详解

    本篇文章是对php strtotime函数的使用进行了详细的分析介绍,需要的朋友参考下

    PHP strtotime函数用法、实现原理和源码分析

    主要介绍了PHP strtotime函数用法、实现原理和源码分析,本文讲解了strtotime函数的一些用法、strtotime函数的实现基本原理、strtotime(“-1 month”)求值失败的原因等内容,需要的朋友可以参考下

    php strtotime 函数UNIX时间戳

    int strtotime ( string time [, int now])本函数预期接受一个包含英文日期格式的字符串并尝试将其解析为 UNIX 时间戳。

    PHP中strtotime函数使用方法分享

    一,获取指定日期的unix时间戳 strtotime(“2009-1-22”) 示例如下: 1.echo strtotime(“2009-1-22”) 结果:1232553600 说明:返回2009年1月22日0点0分0秒时间戳 二,获取英文文本日期时间 示例如下: 便于比较,...

Global site tag (gtag.js) - Google Analytics