strtotime

PHP时间函数

坚强是说给别人听的谎言 提交于 2020-01-28 19:24:48
PHP输出时间差函数 <?php date_default_timezone_set('PRC'); //默认时区 echo "今天:",date("Y-m-d",time()),"<br>"; echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"<br>"; echo "昨天:",date("Y-m-d",strtotime("-1 day")), "<br>"; echo "明天:",date("Y-m-d",strtotime("+1 day")), "<br>"; echo "一周后:",date("Y-m-d",strtotime("+1 week")), "<br>"; echo "一周零两天四小时两秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "<br>"; echo "下个星期四:",date("Y-m-d",strtotime("next Thursday")), "<br>"; echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."<br>"; echo "一个月前:".date("Y-m-d",strtotime("last month"))."<br>";

php时间函数应用

二次信任 提交于 2020-01-28 04:52:03
一,PHP时间戳函数获取指定日期的unix时间戳 strtotime(”2009-1-22″) 示例如下: echo strtotime(”2009-1-22″) 结果:1232553600 说明:返回2009年1月22日0点0分0秒时间戳 二,PHP时间戳函数获取英文文本日期时间 示例如下: 便于比较,使用date将当时间戳与指定时间戳转换成系统时间 (1)打印明天此时的时间戳strtotime(”+1 day”) 当前时间:echo date(”Y-m-d H:i:s”,time()) 结果:2009-01-22 09:40:25 指定时间:echo date(”Y-m-d H:i:s”,strtotime(”+1 day”)) 结果:2009-01-23 09:40:25 (2)打印昨天此时的时间戳strtotime(”-1 day”) 当前时间:echo date(”Y-m-d H:i:s”,time()) 结果:2009-01-22 09:40:25 指定时间:echo date(”Y-m-d H:i:s”,strtotime(”-1 day”)) 结果:2009-01-21 09:40:25 (3)打印下个星期此时的时间戳strtotime(”+1 week”) 当前时间:echo date(”Y-m-d H:i:s”,time()) 结果:2009-01-22 09

php 时间问题

情到浓时终转凉″ 提交于 2020-01-26 02:32:46
获得简单的日期 date() 函数的格式参数是必需的,它们规定如何格式化日期或时间。 下面列出了一些常用于日期的字符: d - 表示月里的某天(01-31) m - 表示月(01-12) Y - 表示年(四位数) 1 - 表示周里的某天 其他字符,比如 "/", "." 或 "-" 也可被插入字符中,以增加其他格式。 下面的例子用三种不同方法格式今天的日期: 实例 <?php echo "今天是 " . date("Y/m/d") . "<br>"; echo "今天是 " . date("Y.m.d") . "<br>"; echo "今天是 " . date("Y-m-d") . "<br>"; echo "今天是 " . date("l");//L的小写 ?>效果: 获得简单的时间 下面是常用于时间的字符: h - 带有首位零的 12 小时小时格式 i - 带有首位零的分钟 s - 带有首位零的秒(00 -59) a - 小写的午前和午后(am 或 pm) 下面的例子以指定的格式输出当前时间: 实例 <?php echo "现在时间是 " . date("h:i:sa"); ?> 通过 PHP mktime() 创建日期 date() 函数中可选的时间戳参数规定时间戳。如果您未规定时间戳,将使用当前日期和时间(正如上例中那样)。 mktime() 函数返回日期的 Unix

strtotime returning false date

荒凉一梦 提交于 2020-01-24 23:32:09
问题 I have a problem with strtotime function in php, i'm trying to convert mm-dd-yyyy to yyyy-mm-dd. The date is entered on the text box and on submit it should save the date to the database. the problem is it returns a wrong date(1970-01-01) each time,which means my code isn't taking the variable i use to store the date, My code is: //dateconvert $submitdate = date($_POST['date']); $date = date("Y-m-d", strtotime($submitdate)); //storeindb $query ="INSERT INTO ticket SET date = '$date'"; $result

前端学PHP之日期与时间

雨燕双飞 提交于 2020-01-23 00:30:01
前面的话   在Web程序开发时,时间发挥着重要的作用,不仅在数据存储和显示时需要日期和时间的参与,好多功能模块的开发,时间通常都是至关重要的。网页静态化需要判断缓存时间、页面访问消耗的时间需要计算、根据不同的时间段提供不同的业务等都离不开时间。PHP为我们提供了强大的日期和时间处理功能,通过内置的时间和日期函数库,不仅能够得到PHP程序在运行时所在服务器中的日期和时间,还可以对它们进行任意检查和格式化,以及在不同格式之间进行转换等。本文将详细介绍PHP中的日期和时间   [注意]关于javascript的日期和时间相关内容请 移步至此 时间戳   UNIX时间戳是保存日期和时间的一种紧凑简洁的方法,是大多数UNIX系统中保存当前日期和时间的一种方法,也是在大多数计算机语言中表示日期和时间的一种标准格式。UNIX时间戳是从1970年1月1日0点(UTC/GMT的午夜)开始起到当前时间所经过的秒数   因为UNIX时间戳是一个32位的数字格式,所以特别适用于计算机处理,例如计算两个时间点之间相差的天数。另外,由于文化和地区的差异,存在不同的时间格式,以及时区的问题。所以,UNIX时间戳也是根据一个时区进行标准化而设计的一种通用格式,并且这种格式可以很容易地转换为任何格式   也因为UNIX时间戳是一个32位的整数表示的,所以在处理1902年以前或2038年以后的事件,将会遇到一些问题

Correct input values of strtotime

杀马特。学长 韩版系。学妹 提交于 2020-01-22 03:18:06
问题 I want to convert a date by the following statement $date=date('d M Y, H:m',strtotime($date)); It printed out 09 Sep 2012, 11:09 when I tried various values of $date: 11:00 AM Sunday, 09 Sep 2012 Sunday 09 Sep 2012, 11:00 AM 09 Sep 2012 11:00 AM What date format does the strtotime() function need? It seems to me at least one of them meets the "English textual datetime description" condition. 回答1: Valid formats for strtotime are detailed here. 回答2: From this site (http://www.tuxradar.com

strtotime 踩坑记录

戏子无情 提交于 2020-01-21 05:19:48
前言 今天是 2019 年的最后一天,即将从 2019 年咸鱼进化成 2020 年咸鱼 就在今早,代码写着写着就出现了一个奇怪的事情: echo date('Y/m/d', strtotime('-1 month')); // 2019/12/01 见鬼了,还能不能好好让我当一条咸鱼了? echo date('Y/m/d', strtotime('-2 month')); // 2019/10/31 唔。。。来看看鸟哥怎么说: 令人困惑的 strtotime date 内部处理逻辑 先做 -1 month :今天是 2019/12/31,上个月的今天就是 2019/11/31 再做日期规范化:因为 11 月没有 31 号,自然成了 12 月的 1 号 验证一下: echo date('Y/m/d', strtotime('-1 month', strtotime('2019/03/31'))); // 2019/03/03 那我该如何获取上个月的最后一天日期呢? 相对格式 echo date('Y/m/d', strtotime('last day of -1 month')); // 2019/11/30 相对格式 最后 问题解决,继续当回一条可爱的咸鱼。 原文链接: https://learnku.com/articles/38975 来源: CSDN 作者: 韩某Hyman

PHP时间函数

感情迁移 提交于 2020-01-20 13:39:39
PHP时间函数 2. echo date('Y-m-d H:i:s',strtotime('now'));//当前时间戳 2017-01-09 21:04:11 3. echo date('Y-m-d H:i:s',time()); 4. echo date('Y-m-d H:i:s',strtotime('+1second'));//当前时间戳+1秒 2017-01-09 21:04:12 5. 6. echo date('Y-m-d H:i:s',strtotime('+1minute'));//当前时间戳+1分 2017-01-09 21:05:11 7. 8. echo date('Y-m-d H:i:s',strtotime('+1hour'));//当前时间戳+1小时 2017-01-09 22:04:11 9. 10. echo date('Y-m-d H:i:s',strtotime('+1day'));//当前时间戳+1天 2017-01-10 21:04:11 11. 12. echo date('Y-m-d H:i:s',strtotime('+1week'));//当前时间戳+1周 2017-01-16 21:04:11 13. 14. echo date('Y-m-d H:i:s',strtotime('+1month'));//当前时间戳+1月 2017

PHP check if timestamp is greater than 24 hours from now

旧城冷巷雨未停 提交于 2020-01-14 07:26:23
问题 I have software that needs to determine if the cutoff datetime is greater than 24 hours from now. Here is the code I have to test that. $date = strtotime("2013-07-13") + strtotime("05:30:00"); if($date > time() + 86400) { echo 'yes'; } else { echo 'no'; } My current date and time is 2013-07-13 2am. As you can see its only 3 hours away. At my math thats 10800 seconds away. The function I have is returning yes . To me this is saying the $date is greater than now plus 86400 seconds when in fact

Using FQL to retrieve only upcoming birthdays from Facebook API

情到浓时终转凉″ 提交于 2020-01-12 10:17:30
问题 Using the information on FQL and the user table from Facebook's Developer's docs, I've come up with the following code. //build fql string $fql = "SELECT name, birthday_date FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND strlen(birthday_date) != 0 AND substr(birthday_date,0,3) IN ('{$currentMonth}/', '{$nextMonth}/')"; $fql.=$orderBy; $fql.=" LIMIT " . $limit; //query facebook $params = array( 'method' => 'fql.query', 'query' => $fql, 'callback' => '' ); $birthdays =