`

php中挺好用的strtotime方法

    博客分类:
  • PHP
阅读更多
  在PHP中,经常要对日期进行计算,比如要计算一个月前的日期,那么其实最快的方法
是用strtotime,其功能很丰富,如下:


echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";


  看到没 +1 day  +1 week,马上求出1天后,1个星期后的日期了,
求1个月前,可以:
echo date('Y-m-d', strtotime('1 month ago'))

  因此,判断是否一个月前,可以
if  strtotime($my_date) < strtotime('1 month ago'))
2
0
分享到:
评论

相关推荐

    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使用date和strtotime函数输出指定日期的方法

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

    PHP中strtotime函数使用方法详解

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

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

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

    PHP中strtotime函数使用方法分享

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

    php中strtotime函数性能分析

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

    PHP strtotime函数详解

    先看手册介绍: strtotime — 将任何英文文本的日期时间描述解析为 Unix 时间戳 格式:int strtotime ( string $time ...自 PHP 5.1.0 起有更容易的方法来定义时区用于所有的日期/时间函数。此过程在 date_default_tim

    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中strtotime函数用法详解

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

    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函数的使用详解

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

    js模仿php中strtotime()与date()函数实现方法

    本文实例讲述了js模仿php中strtotime()与date()函数实现方法。分享给大家供大家参考。具体如下: 在js中没有像php中strtotime()与date()函数,可直接转换时间戳,下面我们来自定一个函数来实现js中具体有时间戳转换...

    php中url地址栏传参数中文乱码解决方法汇总

    php中url地址栏传参数中文乱码解决方法汇总

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

    源码位置:\ext\date\php_date.c 复制代码 代码如下: ...PHP_FUNCTION(strtotime) {  char *times, *initial_ts;  int time_len, error1, error2;  struct timelib_error_container *error;  lon

Global site tag (gtag.js) - Google Analytics