strtotime

PHP自定义函数+系统函数库

て烟熏妆下的殇ゞ 提交于 2020-01-10 11:44:42
全局变量 $n = 5; //全局变量 function fun1(){ global $n; echo '我在函数体内也可以调用全局变量n,它的值是:' , $n;//5 $n++; } fun1(); echo '<hr>'; echo $n;//6 $n = 6; function fun1(){ echo '变量的值是:' , $GLOBALS['n']; $GLOBALS['n']++; } fun1(); echo $GLOBALS['n']; 不使用循环语句,来计算1~100的和 function recursive($n){ if($n>=1){ return $n + recursive($n-1); } } echo recursive(100); 引用 $foo = 'Bob'; $bar = &$foo; //看待成变量的别名 $bar = 'Rose'; echo $foo;//Rose $foo = 'Mooc'; $bar = &$foo; //看待成变量的别名 unset($foo); //变量销毁 echo $bar;//Mooc 自定义函数 function fun1(&$n){ $n++; echo '我是函数体内的局部变量' , $n ;//4 } $n = 3; fun1($n); echo $n , '<hr>';//4 获得扩展名

Adding years to a date resets to 1970-01-01

送分小仙女□ 提交于 2020-01-09 11:19:32
问题 $somedate = "1980-02-15"; $otherdate = strtotime('+1 year', strtotime($somedate)); echo date('Y-m-d', $otherdate); outputs 1981-02-15 and $somedate = "1980-02-15"; $otherdate = strtotime('+2 year', strtotime($somedate)); echo date('Y-m-d', $otherdate); outputs 1982-02-15 but $somedate = "1980-02-15"; $otherdate = strtotime('+75 year', strtotime($somedate)); echo date('Y-m-d', $otherdate); outputs 1970-01-01 How to fix? 回答1: It's the 2038 bug which is like y2k where systems can't handle dates

Get the year of a specified month in previous 12 months?

走远了吗. 提交于 2020-01-06 18:05:53
问题 I'm trying: $m = 'December'; $from = date('jS M Y', strtotime("first day of previous $m")); But it's not returning a date. In use, the month will be selected by a user from a dropdown box. However, I have tried typing 'December' in place of the variable directly and it still doesn't work. I'm expecting it to return "1st Dec 2012". 回答1: Given your code that $m is the current month in text format, you can use something like: $m = 'June'; $m = date('m', strtotime($m)); $c = (mktime(0,0,0,$m, 1)

Get the year of a specified month in previous 12 months?

China☆狼群 提交于 2020-01-06 18:04:07
问题 I'm trying: $m = 'December'; $from = date('jS M Y', strtotime("first day of previous $m")); But it's not returning a date. In use, the month will be selected by a user from a dropdown box. However, I have tried typing 'December' in place of the variable directly and it still doesn't work. I'm expecting it to return "1st Dec 2012". 回答1: Given your code that $m is the current month in text format, you can use something like: $m = 'June'; $m = date('m', strtotime($m)); $c = (mktime(0,0,0,$m, 1)

Server strtotime incorrect

时光毁灭记忆、已成空白 提交于 2020-01-06 02:14:37
问题 Both strtotime and mktime are outputting an incorrect timestamp and it's driving me mad. If I add the following strtotime('2012-10-09'); I get 1349701200 Which is actually Mon, 08 Oct 2012 13:00:00 GMT I'm using my localhost, running MAMP. I'm assuming it's a server timezone issue, or something, but I don't understand why, or how to fix it. Any help? 回答1: strtotime uses default timezone to interpret the string. If you want different timezone you could specify it explicitly or change it for

PHP - Parse datetime with locale strings

百般思念 提交于 2020-01-05 03:36:07
问题 I want to parse datetimes like 'Ayer, 16:08' which is 'Yesterday, 16:08' in spanish. I have tried this $dateString = 'Ayer, 16:08'; setlocale(LC_ALL, 'es'); $time = strtotime($dateString); echo date('d-m-Y H:i', $time); but it echoes 01-01-1970 00:00 Nevertheless, if I do it with english strings it works just fine: $dateString = 'Yesterday, 16:08'; $time = strtotime($dateString); echo date('d-m-Y H:i', $time); Is it a problem with locale? Thanks 回答1: You'll need to translate it into English

Get month after and before given month name

筅森魡賤 提交于 2020-01-04 04:46:07
问题 How do I get the month name after a given month. So for June, I would want July I have tried: $next_month = date('F',strtotime('June', "next month")); This display January, which is obviously wrong, I am looking for July. How would I then get the month before? I have tried $prev_month = date('F',strtotime('June - 1 month')); 回答1: $next_month = date('F',strtotime('June + 1 month')); or $next_month = date('F',strtotime('June next month')); edit $next_month = date('F',strtotime('June last month'

Check if current time is between two times, with the possibility of lapping days

泪湿孤枕 提交于 2020-01-01 05:43:07
问题 I have a system that accepts user submissions, and upon receiving a submission the system will go through all timeslots to find the appropriate timeslot. The problem is that it needs to be able to check against the start & end times if the end time laps to the next day. Take the following example: A timeslot begins at 10:30 PM on the current day and ends at 4:00 PM the next day. If the current time is between 10:30 PM and 11:59:59 PM, the submission will be assigned to that timeslot. However,

月份获取

我只是一个虾纸丫 提交于 2019-12-31 05:44:38
获取本月日期: 复制代码 代码如下: function getMonth($date){ $firstday = date("Y-m-01",strtotime($date)); $lastday = date("Y-m-d",strtotime("$firstday +1 month -1 day")); return array($firstday,$lastday); } $firstday是月份的第一天,假如$date是2014-2这样的话,$firstday就会是2014-02-01,然后根据$firstday加一个月就是2014-03-01,再减一天就是2014-02-28,用date()和strtotime()真是太方便了。   获取上月日期: 复制代码 代码如下: function getlastMonthDays($date){ $timestamp=strtotime($date); $firstday=date('Y-m-01',strtotime(date('Y',$timestamp).'-'.(date('m',$timestamp)-1).'-01')); $lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day")); return array($firstday,$lastday); }

Can anyone explain why strtotime('cast') returns a value?

筅森魡賤 提交于 2019-12-31 01:48:08
问题 Not really an issue (although it is conflicting with an if() statement we have), but when you type in strtotime('cast'), it returns an actual value that defaults to today's date. I was just wondering if anyone knew what significance the word cast has when it comes to time functions Thanks! 回答1: It maps to the timezone offset for "Australia/Adelaide". Example: echo date('Y-m-d H:i:s'), "\n", date('Y-m-d H:i:s', strtotime("cast")), "\n", date('Y-m-d H:i:s', strtotime("Australia/Adelaide"));