首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏Web技术布道师

    令人困惑的strtotime

    , 都可能会有这个迷惑, 我们也可以很轻松的验证类似的其他月份, 印证这个结论: var_dump(date("Y-m-d", strtotime("-1 month", strtotime("2017 -03-31"))));//输出2017-03-03var_dump(date("Y-m-d", strtotime("+1 month", strtotime("2017-08-31"))));//输出 (date("Y-m-d", strtotime("last month", strtotime("2017-03-31"))));//输出2017-03-03 那怎么办呢? day of +1 month", strtotime("2017-08-31"))));////输出2017-09-01var_dump(date("Y-m-d", strtotime("first day of next month", strtotime("2017-01-31"))));////输出2017-02-01var_dump(date("Y-m-d", strtotime("last

    68820发布于 2019-07-25
  • 来自专栏luxixing

    强大的strtotime函数

    $t = strtotime("-{$n} days 00:00:00");//当前日期的前n天的0点 $t = strtotime("-{$n} days 23:00:00");//当前日期的前n天的 strtotime("+{$n} days 00:00:00");//当前日期的后n天的0点 $t = strtotime("+{$n} days 23:00:00");//当前日期的后n天的23点 获取指定日期前 $n*86400 s的时间 $t = strtotime("+{$n} days {$data} 00:00:00");//当前日期的后n天的0点 $t = strtotime("+{$n} days "); $t = strtotime("yesterday 00:00:00"); //以上三个结果一样,但是为了严谨期间,如果需要时分秒,给出精确时间 $t = strtotime("tomorrow "); $t = strtotime("tomorrow midnight"); $t = strtotime("tomorrow 00:00:00"); $year = 2015; $month =

    1.1K30发布于 2019-05-28
  • 来自专栏Web技术布道师

    php 之 strtotime 使用需注意

    var_dump(date('Y-m-d')); var_dump(date('Y-m-d', strtotime('- 1 day'))); var_dump(date('Y-m-d', strtotime ('+ 2 day'))); var_dump(date('Y-m-d', strtotime('- 1 week'))); var_dump(date('Y-m-d', strtotime('+ 2 ("-1 month", strtotime("2018-05-31")))); 打印出来的结果是: string(10) "2018-05-01" !!! 那上面的 2018-05-31 举例子, -1 month 应该是 2018-04-31 ,但是4月没有31号, 所以结果就是 2018-05-01 如果要获取 上一个月最后一天 ,可以使用 last day of -1 month 来获取,如下图所示 var_dump(date("Y-m-d", strtotime("last day of -1 month", strtotime("2018-05

    60520发布于 2019-07-25
  • 来自专栏陶士涵的菜地

    重回基础(date函数和strtotime函数)

    ():把字符串类型日期格式转成时间戳 使用函数strtotime(),打印前一天日期,参数:String类型 “-1 day” echo date("Y-m-d H:i:s",strtotime("-1day "));输出 2016-05-12 15:27:33 使用函数strtotime(),打印明天日期,参数:String类型 “+1 day” echo date("Y-m-d H:i:s",strtotime s",strtotime("+1 week"));;输出 2016-05-20 15:29:35 使用函数strtotime(),打印下一个月日期,参数:String类型 “+1 month” echo date("Y-m-d H:i:s",strtotime("+1 month")); 输出:2016-06-13 15:37:42 使用函数strtotime(),打印下周一日期,参数:String类型 “last Mondy” echo date("Y-m-d H:i:s",strtotime("next Monday")); 输出:2016-05-16 00:00:00 使用函数strtotime

    58710发布于 2019-09-10
  • 来自专栏zcqshine's blog

    PHP里 date() 函数与 strtotime() 函数笔记

    ###获取今日0点的时间戳 $today = strtotime(date('Ymd')); $today2 = strtotime('today'); echo "today = ". $today2; 输出: today = 1463500800 today2 = 1463500800 由此可见,获取今日0点时的时间戳可以直接使用strtotime("today").

    1.2K60发布于 2018-05-11
  • 来自专栏codersam

    PHP strtotime(date(Y-m-d) . 00:00:00)获取时间戳不准确的问题

    今天遇到一个BUG,在使用strtotime(date('Y-m-d') . ' 00:00:00') 获取当天零点时间戳会出现不准确的问题,有时候获取的是正常的零点时间戳,有时候获取的是当天8点的时间戳 解决方案: strtotime(date('Y-m-d')) // 获取当天零点时间戳 strtotime(date('Y-m-d') . ' + 1 day') - 1 // 获取当天23点59分59 秒时间戳 strtotime(date('Y-m-d')) - 1 // 获取昨天23点59分59秒时间戳

    3K20发布于 2019-12-17
  • 来自专栏老高的技术博客

    PHP时间函数总结

    运行时定义时区 方法一 ini_set('date.timezone','Asia/Shanghai'); 方法二 date_default_timezone_set('PRC'); //此函数PHP4不存在 , "\n"; echo strtotime("Saturday"), "\n"; echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n"; echo 他用来描述一段时间,形如P1Y2M3DT4H5M6S,字母都是大写。其中P后面跟年月日,T后面是时分秒。 2] => 12 [3] => 27 [4] => 2 [5] => 114 [6] => 4 [7] => 85 [8] => 0 ) 如果第二参数为真 13 [tm_hour] => 12 [tm_mday] => 27 [tm_mon] => 2 [tm_year] => 114 [tm_wday] => 4

    3.2K20编辑于 2022-12-27
  • 来自专栏仙士可博客

    计算在工作日时间推迟时间的算法

        {         foreach ($this->holidayDay as $startDate => $endDate) {             $this->holidayData[strtotime ($startDate)] = strtotime($endDate);         }         ksort($this->holidayData);         foreach ($this ->holidayExtraWorkDay as $startDate => $endDate) {             $this->workDayData [strtotime($startDate ($date));         if (in_array($week, [1, 2, 3, 4, 5])) {//周一到周五             //验证是否为节假日,如果是则不用上班              $startTime)] = strtotime($date . " " . 

    1.2K30编辑于 2022-09-13
  • 获取每天时间戳,每周时间戳,每月时间戳和每年时间戳

    monthNumber = $month; $month = sprintf("%02d", intval($month)); $year = str_pad(intval($year), 4, 59', strtotime("$startstr +6 day"))); $Monthend = strtotime(date('Y-m-d 23:59:59', strtotime("$startstr [array] $data [每月的开始和结束] */ function getMonth($year) { $year = str_pad(intval($year), 4, getMonthDay($year, $month){ $month = sprintf("%02d", intval($month)); $year = str_pad(intval($year), 4, getMonthWeek($year, $month){ $month = sprintf("%02d", intval($month)); $year = str_pad(intval($year), 4,

    4.8K10编辑于 2024-08-16
  • 来自专栏怡文菌

    php如何在某个时间上加一天?一小时? 时间加减

    ",strtotime("+1 day")),"
    "; echo "一周后:",date("Y-m-d",strtotime("+1 week")),"
    "; echo "一周零两天四小时两秒后 :",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "
    "; echo "下个星期四:",date("Y-m-d ",strtotime("next Thursday")),"
    "; echo "上个周一:".date("Y-m-d",strtotime("last Monday"))." > //strtotime可以接受第二个参数,类型timestamp,为指定日期 echo date('Y-m-d', strtotime ("+1 day", strtotime('2011-11-01 ("$d +1 day")); //日期天数相加函数 function dateToTime($d){//把日期转换成时间堆截 $year=((int)substr("$d",0,4)

    3.6K20编辑于 2022-12-15
  • 来自专栏技术博文

    获取某个日期的第几天,倒数第几天

    $day = '2014-03-28';   $d1 = date("Y-m-d", strtotime("0 day $day"));//第1天03-28   $d3 = date("Y-m-d", strtotime("2 day $day"));//第3天   $d7 = date("Y-m-d", strtotime("6 day $day"));//第7天   $d15 = date("Y-m-d ", strtotime("14 day $day"));//第15天   $d30 = date("Y-m-d", strtotime("29 day $day"));//第30天 $rd5 = date ("Y-m-d", strtotime("-4 day $day"));//最后5天   $rd3 = date("Y-m-d", strtotime("-2 day $day"));//最后3天    $rd2 = date("Y-m-d", strtotime("-1 day $day"));//最后2天   $rd1 = date("Y-m-d", strtotime("-0 day $day")

    1.1K40发布于 2018-04-10
  • 来自专栏米扑专栏

    PHP 日期加减计算方法示例

    ",strtotime("+1 day")),"\n";    echo "一周后:",date("Y-m-d",strtotime("+1 week")),"\n";    echo "一周零两天四小时两秒后 :",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "\n";    echo "下个星期四:",date("Y-m-d ",strtotime("next Thursday")),"\n";    echo "上个周一:".date("Y-m-d",strtotime("last Monday"))." H:i:s', strtotime ("+1 day", strtotime('2017-11-11'))), "\n";              // 这里+1 day 可以修改参数1为任何想需要的数 1   day")), "\n\n";        // 把日期转换成时间截    function date2time($d){        $year=((int)substr("$d",0,4)

    2.7K50发布于 2018-05-17
  • 来自专栏吃猫的鱼个人博客编程笔记

    php时间戳,php时间代码合集,时间日期转换

    将年月日时间转换成时间戳 echo strtotime('2020-01-15 11:20:10'); //直接输出转换后的时间戳 当前时间加七天 echo date("Y-m-d H:i:s",strtotime ("+7 day")); //输出七天后的日期 php获取今天日期 date("Y-m-d",strtotime("today")); //strtotime(‘today’)输出今天的开始时间戳 date ("Y-m-d",time()); //time()输出当前秒时间戳 php获取昨天日期 date("Y-m-d",strtotime("-1 day")); date("Y-m-d",strtotime ("yesterday")); //二者都可以实现 php获取明天日期 date("Y-m-d",strtotime("+1 day")); date("Y-m-d",strtotime("tomorrow php获取一周零两天四小时五分钟两秒后时间 date("Y-m-d H:i:s",strtotime("+1 week 2 days 4 hours 5 minute 2 seconds")); php

    5.7K30编辑于 2023-02-02
  • 来自专栏飞鸟的专栏

    PHP- 日期和时间函数

    示例:echo time(); // 输出当前时间戳二、格式化日期和时间字符串strtotime(): 将日期字符串转换为时间戳 strtotime()函数用于将一个日期字符串转换为Unix时间戳。 示例:echo mktime(0, 0, 0, 4, 26, 2023); // 输出指定日期的时间戳date_create(): 创建一个日期对象 date_create()函数用于创建一个日期对象, (): 计算两个日期之间的差值 strtotime()函数可以用于计算两个日期之间的差值。 示例:$date1 = strtotime('2023-04-26');$date2 = strtotime('2023-05-01');echo ($date2 - $date1)/(60*60*24 示例:$date1 = strtotime('2023-04-26');$date2 = strtotime('2023-05-01');if ($date1 < $date2) { echo '

    2.9K30编辑于 2023-04-26
  • 来自专栏林冠宏的技术文章

    PHP 获取 特定时间范围 类

    要查找的时间范围,根据传入参数选择生产,也可以组合 sql 语句返回,本例就是;   2,已实现:       1) 按 日 生成范围        2)按周 生成范围       3)按月 生成范围       4) 按年 生成范围   3,所用语言是 php,服务器解析需要安装 Apache,或者 Nginx;   4,格式是时间戳,切记,拥有时间戳,就可以任意处理,可以生产这种日期时间格式: 2016-7-08 php 2 /** 3 * Created by PhpStorm. 4 * Author: 林冠宏 5 * Date: 2016/6/4 6 * Time: 16:06 )); // 获取传过来的月所有天数 152 $timeF = strtotime($selectTime); 153 } 154 $timeL "-1-1"); 171 $year = (int)$selectTime + 1; 172 } 173 $timeL = strtotime($

    2.9K100发布于 2018-01-03
  • 来自专栏linux 自动化运维

    php 获取指定日期是的星期几,根据本周周一时间 获取本周时间对应的7天星期

    $day1+3; $day5=$day1+4; $day6=$day1+5; $day7=$day1+6; $date1=$yue."-". $day3; $date4=$yue."-".$day4; $date5=$yue."-".$day5; $date6=$yue."-".$day6; $date7=$yue."-". ]; $week2=$weekarray[date("w",strtotime("$date2"))]; $week3=$weekarray[date("w",strtotime("$date3"))] ; $week4=$weekarray[date("w",strtotime("$date4"))]; $week5=$weekarray[date("w",strtotime("$date5"))]; $week6=$weekarray[date("w",strtotime("$date6"))]; $week7=$weekarray[date("w",strtotime("$date7"))];

    3.1K40发布于 2021-05-20
  • 来自专栏WordPress果酱

    告别相差8小时问题,在 WordPress 正确使用 Date 和 Time

    wpjam_strtotime 前面解决了在 WordPress 中基于时间戳正确显示时间的问题,然后还有一个常见的操作就是将日期转换为日期戳,PHP 提供了一个 strtotime 的函数: echo 所以为了方便将当地时间正确转换成时间戳,所以我写了一个函数 wpjam_strtotime: function wpjam_strtotime($string){ return date_create ("2022-11-21 23:15:45"); // 1669043745 wpjam_strtotime 很快会在 WPJAM Basic 新版本中发布,所以有了第二条规则:在 WordPress 进行日期和时间转换成时间戳操作的时候,把 strtotime 函数替换成 wpjam_strtotime 函数即可。 将日期和时间转换成时间戳的时候:把 strtotime 函数替换成 wpjam_strtotime 函数。

    1.5K30编辑于 2023-04-13
  • 来自专栏全栈程序员必看

    php 字符串转换时间_php 字符时间如何转换「建议收藏」

    strtotime() strtotime() 函数用于将英文文本字符串表示的日期转换为时间戳,为 date() 的反函数,成功返回时间戳,否则返回 FALSE 。 php echo strtotime(“2009-10-21 16:00:10”); //输出 1256112010 echo strtotime(“10 September 2008”); //输出 1220976000 echo strtotime(“+1 day”), “ “; //输出明天此时的时间戳 ? > 自定义函数 下面的函数与strtotime功能差不多。<? time_str = str_format_time(date_str); function str_format_time($timestamp = ”) { if (preg_match(“/[0-9]{4}

    10.3K20编辑于 2022-09-05
  • 来自专栏前端资源

    PHP获取当前时间、年份、月份、日期和天数

    两位数字:19) F - 表示月份(完整的文本格式: January 或者 March) M - 表示月份(3个字母:Jun) m - 表示月份,有前导0(数字:04) n - 表示月份,无前导0(数字:4) > 运行结果: 创建日期是:2015-06-10 09:12:31AM 通过 PHP strtotime() 用字符串来创建日期 PHP strtotime() 函数用于把人类可读的字符串转换为 Unix 语法: strtotime(time,now) 通过 strtotime() 函数创建日期和时间: 实例: <? php     $d=strtotime("tomorrow");     echo date("Y-m-d h:i:sa", $d) .  php     $startdate = strtotime("Saturday");     $enddate = strtotime("+6 weeks",$startdate);          

    27.3K10发布于 2019-11-12
  • 来自专栏全栈程序员必看

    计算一段日期内的周末天数(星期六,星期日总和)(

    id=343578′ scrolling=’no’>function get_weekend_days($start_date,$end_date){ if (strtotime($start_date ) > strtotime($end_date)) list($start_date, $end_date) = array($end_date, $start_date); $start_reduce = $end_add = 0; $start_N = date(‘N’,strtotime($start_date)); $start_reduce = ($start_N == 7) ? 1 : 0; $end_N = date(‘N’,strtotime($end_date)); in_array($end_N,array(6,7)) && $end_add = ($end_N = 2 : 1; $days = abs(strtotime($end_date) – strtotime($start_date))/86400 + 1; return floor(($days +

    1.7K20编辑于 2022-09-07
领券