, 都可能会有这个迷惑, 我们也可以很轻松的验证类似的其他月份, 印证这个结论: 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
$t = strtotime("-{$n} days 00:00:00");//当前日期的前n天的0点 $t = strtotime("-{$n} days 23:00:00");//当前日期的前n天的 $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 $month} 11:00:00");//指定月份的第一天11点 $t = strtotime("last day of {$year}-{$month} 11:00:00");//指定月份的最后一天 $t = strtotime("last day of {$year}-{$month} 11:00:00");//指定月份的最后一天11点 以上仅仅是一小部分 ps 使用 +|- days[month
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 week'))); 打印出来的结果是: string(10) "2018-10-09" string(10) "2018-10-08" string(10) "2018-10-11" string(10 ("-1 month", strtotime("2018-05-31")))); 打印出来的结果是: string(10) "2018-05-01" !!! ("last day of -1 month", strtotime("2018-05-31")))); 打印结果是: string(10) "2017-04-30" 为了避免 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
###获取今日0点的时间戳 $today = strtotime(date('Ymd')); $today2 = strtotime('today'); echo "today = ". $today2; 输出: today = 1463500800 today2 = 1463500800 由此可见,获取今日0点时的时间戳可以直接使用strtotime("today").
-21 23:15:45 如果我们在 WordPress 也这么使用,将会输出:2022-11-21 15:15:45,将会相差8小时,这是为什么呢? strtotime("2022-11-21 23:15:45"); // 1669072545 和上面输入的 1669043745 也是相差 8x3600,也是8小时,同样的原因,这个函数也是基于系统默认的时区的 ("2022-11-21 23:15:45"); // 1669043745 wpjam_strtotime 很快会在 WPJAM Basic 新版本中发布,所以有了第二条规则:在 WordPress 进行日期和时间转换成时间戳操作的时候,把 strtotime 函数替换成 wpjam_strtotime 函数即可。 将日期和时间转换成时间戳的时候:把 strtotime 函数替换成 wpjam_strtotime 函数。
> 运行结果: 1234567891011 今天:2017-11-06今天:2008-06-18昨天:2017-11-05明天:2017-11-07一周后:2017-11-13一周零两天四小时两秒后: 2017-11-15 22:22:42下个星期四:2017-11-09上个周一:2017-10-30一个月前:2017-10-06一个月后:2017-12-06十年后:2027-11-06 PHP 进阶的日期加减计算 H:i:s', strtotime ("+1 day", strtotime('2017-11-11'))), "\n"; // 这里+1 day 可以修改参数1为任何想需要的数 > 运行结果: 今天: 2017-11-06 18:58:04 明天: 2017-11-07 18:58:04 2017-11-12 00:00:00 2017-11-07 19:59:04 PHP > 运行结果: 1234567891011 2017-11-06 19:13:022016-09-13 14736096002016-09-122019-11-132016-09-13 1473609600
echo date(‘Y-m-d H s’,strtotime(‘now’));//当前时间戳 2017-01-09 21:04:11 echo date(‘Y-m-d H s’,strtotime(‘ -01-09 21:05:11 echo date(‘Y-m-d H s’,strtotime(‘+1hour’));//当前时间戳+1小时 2017-01-09 22:04:11 echo date( ‘Y-m-d H s’,strtotime(‘+1day’));//当前时间戳+1天 2017-01-10 21:04:11 echo date(‘Y-m-d H s’,strtotime(‘+1week ’));//当前时间戳+1周 2017-01-16 21:04:11 echo date(‘Y-m-d H s’,strtotime(‘+1month’));//当前时间戳+1月 2017-02-09 21:04:11 echo date(‘Y-m-d H s’,strtotime(‘+1year’));//当前时间戳+1年 2018-01-09 21:04:11 echo date(‘Y-m-d H
",strtotime("+1 day")),"
";
echo "一周后:",date("Y-m-d",strtotime("+1 week")),"
";
echo "一周零两天四小时两秒后 ",strtotime("next Thursday")),"
";
echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."
";
echo "一个月后:".date("Y-m-d",strtotime("+1 month"))." >
//strtotime可以接受第二个参数,类型timestamp,为指定日期
echo date('Y-m-d', strtotime ("+1 day", strtotime('2011-11-01 echo date('Y-m-d',strtotime('+1 d',strtotime('2009-07-08')));//日期天数相加函数
echo date("Y-m-d",'1246982400
将年月日时间转换成时间戳 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获取7天后日期 date("Y-m-d",strtotime("+7 day")); 以此类推,需要获取多久后的日期就+多少day即可!
echo strtotime("2014-03-27"), "\n"; echo strtotime("December 31"), "\n"; echo strtotime("now"), "\n"; echo strtotime("10 September 2000"), "\n"; echo strtotime("+1 day"), "\n"; echo strtotime("+1 week") strtotime("next Thursday"), "\n"; echo strtotime("last Monday"), "\n"; 还可以指定日期 $time = date('Y-m-d H :i:s', time()); echo strtotime($time.'1day'), "\n"; echo "\n"; echo strtotime($time tm_min" - 分钟数, 0 到 59 "tm_hour" - 小时, 0 到 23 "tm_mday" - 月份中的第几日, 1 到 31 "tm_mon" - 年份中的第几个月, 0 (Jan) 到 11
strtotime : strtotime() 函数将任何英文文本的日期或时间描述解析为 Unix 时间戳
substr(string,start,length):
string : 必需。 天
"; $hour=floor((strtotime($enddate)-strtotime($startdate))%86400/3600); echo "相差小时数:". 小时
"; $minute=floor((strtotime($enddate)-strtotime($startdate))%86400/60); echo"相差分钟数:". 分钟
"; $second=floor((strtotime($enddate)-strtotime($startdate))%86400%60); echo"相差秒数:". substr($value['create_time'], 8, 2); //获取创建日期:单位:日
$h = substr($value['create_time'], 11
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功能差不多。<? php $date_str = “2011-09-11 17:00:00”; echo time_str = str_format_time(date_str); function str_format_time
android 移动开发者,而不是一个 phper,如果说只做移动端的 APP , 10 * 我也不会学这么多,这么 2年来,几乎素有的服务器接口都也是 由我一手操办,用的是 pHp,目前大三, 11 ","2015-5"); 49 $this->GetTimeRang("月","2016-7"); 50 $this->GetTimeRang("月","2016-11 (date("Y-m-d",time())); 93 }else{ 94 $timeF = strtotime($selectTime); 95 )); // 获取传过来的月所有天数 152 $timeF = strtotime($selectTime); 153 } 154 $timeL "-1-1"); 171 $year = (int)$selectTime + 1; 172 } 173 $timeL = strtotime($
date("Y年m月d日"); 运行结果: 今天是:2019年04月24日 获得简单的时间: 常用于时间的字符: H - 24小时格式,有前导0(08,18) h - 12小时格式,有前导0(06,11 > 运行结果: 创建日期是: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);
"-"); var datum = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3]-8,arr[4],arr[5])); return strtotime timestr.toLocaleString().replace(/年|月/g, "-").replace(/日/g, " "); return datetime; } 使用方法: var strtotime = 1408502536; var rst_date_time = dateTotime(strtotime ); document.write("日期: "+rst_date_time); 测试示例 : 时间戳: 1366386048 日期: 2013/4/19 下午11:40:48
php #php日期转中文 $str = '2014-10-11'; echo str_replace(str_split('0123456789'), str_split('零一二三四五六七八九 ',3), date('Y',strtotime($str)).' 年'.trim(str_replace('1十','十',implode('十', str_split(date('n',strtotime($str))))),'0').' 月'.trim(str_replace('1十','十',implode('十', str_split(date('d',strtotime($str))))),'0')).'日'; ?>
这里附带一小段代码 $start = "2019-9-17 15:11:38"; $end = "2019-9-01 15:11:45"; $diff = strtotime($start) - strtotime($end); $diffHour = bcdiv($diff, 60 * 60, 2); // 差距的小时 $diffDay = bcdiv($diffHour,24,2); /
今天遇到一个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秒时间戳
string */ function newDate(curformat=’Y-m-d H:i:s’, utc_value) { if(utc_value>2147483647)//2038-01-19 11 time : strtotime(time); // return date(format, time); if(time>2147483647)//2038-01-19 11:14:07 { string = mydate2->format(format); }else{ string = date(format, str_time) { result = strtotime(str_time); if