strtotime

strtotime大小月问题

喜夏-厌秋 提交于 2019-11-26 14:04:24
var_dump(date("Y-m-d", strtotime("-1 month", strtotime("2017-03-31")))); //输出2017-03-03 var_dump(date("Y-m-d", strtotime("+1 month", strtotime("2017-08-31")))); //输出2017-10-01 var_dump(date("Y-m-d", strtotime("next month", strtotime("2017-01-31")))); //输出2017-03-03 var_dump(date("Y-m-d", strtotime("last month", strtotime("2017-03-31")))); //输出2017-03-03 var_dump(date("Y-m-d", strtotime("last day of -1 month", strtotime("2017-03-31")))); //输出2017-02-28 var_dump(date("Y-m-d", strtotime("first day of +1 month", strtotime("2017-08-31")))); ////输出2017-09-01 var_dump(date("Y-m-d", strtotime("first

php function for get all mondays within date range

醉酒当歌 提交于 2019-11-26 13:47:10
问题 Example: $startDate is Monday 2007-02-05 and $endDate is Tuesday 2007-02-20. Then I want it to list: Monday 2007-02-05 Monday 2007-02-12 Monday 2007-02-19 I looked at the PHP manual and found this to get all the days between two dates. But how to do it the way i want? PHP Code: 回答1: Rather than get all days and loop through them all, get the first Monday after the start date and then iterate 7 days at a time: $endDate = strtotime($endDate); for($i = strtotime('Monday', strtotime($startDate));

How to get closest date compared to an array of dates in PHP

≯℡__Kan透↙ 提交于 2019-11-26 12:44:18
问题 This post almost answered this question for me, but I have a specific need and didn\'t find what I sought there. This lies right outside my experience; couldn\'t quite wrap my head around it, so all I really need is a point in the right direction. Let\'s say I have an array as follows: array(5) { [0]=> \"2013-02-18 05:14:54\" [1]=> \"2013-02-12 01:44:03\" [2]=> \"2013-02-05 16:25:07\" [3]=> \"2013-01-29 02:00:15\" [4]=> \"2013-01-27 18:33:45\" } I would like to have a way to provide a date (\

PHP strtotime +1 month adding an extra month [duplicate]

♀尐吖头ヾ 提交于 2019-11-26 12:29:32
问题 This question already has answers here : PHP: Adding months to a date, while not exceeding the last day of the month (5 answers) Closed 6 years ago . I have a simple variable that adds one month to today: $endOfCycle = date(\"Y-m\", strtotime(\"+1 month\")); Today is January 2013, so I would expect to get back 2013-02 but I\'m getting 2013-03 instead. I can\'t figure out why it\'s jumping to March. 回答1: It's jumping to March because today is 29th Jan, and adding a month gives 29th Feb, which

php strtotime “last monday” if today is monday?

独自空忆成欢 提交于 2019-11-26 10:57:47
问题 I want to use strtotime(\"last Monday\") . The thing is, if today IS MONDAY, what does it return? It seems to be returning the date for the monday of last week. How can I make it return today\'s date in that case? 回答1: How can I make it return today's date in that case? pseudocode: if (today == monday) return today; else return strtotime(...); Btw, this trick also could work: strtotime('last monday', strtotime('tomorrow')); 回答2: If you read the manual, there is an great example that describes

php获取前一小时、前一天、三天前、前一个月、三个月前、前一年的时间

社会主义新天地 提交于 2019-11-26 10:03:40
php获取前一个小时的时间: $mtime= date("Y-m-d H:i:s", strtotime("-1 hour")); php获取前一天的时间: $mtime= date("Y-m-d H:i:s", strtotime("-1 day")); php获取三天前的时间: $mtime= date("Y-m-d H:i:s", strtotime("-3 day")); php获取前一个月的时间: $mtime= date("Y-m-d H:i:s", strtotime("-1 month")); php获取三个月前的时间: $mtime= date("Y-m-d H:i:s", strtotime("-3 month")); php获取前一年的时间: $mtime= date("Y-m-d H:i:s", strtotime("-1 year")); 来源: https://www.cnblogs.com/pcx105/p/11933345.html

What is a Unix timestamp and why use it?

陌路散爱 提交于 2019-11-26 08:18:50
问题 What is a Unix timestamp? In PHP, when working with dates, the function strtotime() outputs some integer value -- what is that? I tried to learn about this but I couldn\'t get satisfactory answer, especially why do we need to convert dates using strtotime() . 回答1: What is a Unix Timestamp Simply put, the Unix timestamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970 at UTC. Therefore, the Unix timestamp is merely the number of

PHP's strtotime() in Java

假装没事ソ 提交于 2019-11-26 08:15:33
问题 strtotime() in PHP can do the following transformations: Inputs: strtotime(’2004-02-12T15:19:21+00:00′); strtotime(’Thu, 21 Dec 2000 16:01:07 +0200′); strtotime(’Monday, January 1st’); strtotime(’tomorrow’); strtotime(’-1 week 2 days 4 hours 2 seconds’); Outputs: 2004-02-12 07:02:21 2000-12-21 06:12:07 2009-01-01 12:01:00 2009-02-12 12:02:00 2009-02-06 09:02:41 Is there an easy way to do this in java? Yes, this is a duplicate. However, the original question was not answered. I typically need

How to get previous month and year relative to today, using strtotime and date?

蓝咒 提交于 2019-11-26 08:15:30
问题 I need to get previous month and year, relative to current date. However, see following example. // Today is 2011-03-30 echo date(\'Y-m-d\', strtotime(\'last month\')); // Output: 2011-03-02 This behavior is understandable (to a certain point), due to different number of days in february and march, and code in example above is what I need, but works only 100% correctly for between 1st and 28th of each month. So, how to get last month AND year (think of date(\"Y-m\") ) in the most elegant

Getting all dates for Mondays and Tuesdays for the next year

只谈情不闲聊 提交于 2019-11-26 07:44:46
问题 I need to output a list of dates (only Mondays and Tuesdays) for the next 12 months from current date like so: Jan 2010 Tue 12 Jan 2010 Mon 18 Jan 2010 Tue 19 Jan 2010 Mon 25 Jan 2010 Feb 2010 Tue 02 Feb 2010 Mon 08 Feb 2010 Tue 09 Feb 2010 Mon 15 Feb 2010 Tue 16 Feb 2010 Mon 22 Feb 2010 Mar 2010 Tue 09 Mar 2010 Mon 15 Mar 2010 Tue 16 Mar 2010 ... Being new to PHP I figured strtotime and looping over the next 52 weeks is the best way to go. $blockedDatesInput = \"08 Mar 2010,12 Apr 2010\"; //