strtotime

Issue with php strtotime function when using ordinal values

孤街醉人 提交于 2019-12-21 18:03:38
问题 I sometime get unexpected results when using ordinal values with strtotime. For example, why does date("M j", strtotime("second Tuesday February 2011")) result in "Feb 15" (which is actually the third Tuesday in 2011? 回答1: You are missing an 'of'. $ php -r 'echo date("M j", strtotime("second Tuesday February 2011"));' Feb 15 $ php -r 'echo date("M j", strtotime("second Tuesday of February 2011"));' Feb 8 PHP Version: $ php -v PHP 5.3.3 (cli) (built: Aug 22 2010 19:41:55) Copyright (c) 1997

strtotime result makes no sense, php bug?

旧时模样 提交于 2019-12-21 06:55:27
问题 The following line: echo date('d', strtotime('First Saturday August 2015')); prints 08 , which doesn't seem to make any sense because the first occurrence of a day of the week can't be after the 7th. Is it a php bug or a php bug or maybe even a php bug? I don't know... php version: 5.5.19 回答1: Update #1: explained below the big difference that a simple word like " of " makes, after I investigated a little in the PHP source code. Update #2: There actually is a documentation page on PHP manual

strtotime result makes no sense, php bug?

柔情痞子 提交于 2019-12-21 06:55:04
问题 The following line: echo date('d', strtotime('First Saturday August 2015')); prints 08 , which doesn't seem to make any sense because the first occurrence of a day of the week can't be after the 7th. Is it a php bug or a php bug or maybe even a php bug? I don't know... php version: 5.5.19 回答1: Update #1: explained below the big difference that a simple word like " of " makes, after I investigated a little in the PHP source code. Update #2: There actually is a documentation page on PHP manual

PHP - Strtotime - Add hours

强颜欢笑 提交于 2019-12-21 04:06:28
问题 I have this variable: $timestamp = strftime("%Y-%m-%d %h:%M:%S %a", time ()); I simply want to add three hours and echo it out. I have seen the way where you can do the 60 * 60 * 3 method or the hard code "+ 3 hours" where it understands the words. What is the best way of getting this result? 回答1: $timestamp = strftime("%Y-%m-%d %h:%M:%S %a", time() + 3*60*60) 3*60*60 is the best way 回答2: The best way is what you think is more readable. The following expressions are identical: time() + 3 * 60

Issue with getting week starting from sunday

空扰寡人 提交于 2019-12-19 10:33:36
问题 Following is the function which I have created for getting sunday as a starting day of a week, function getCurrentIntervalOfWeek($liveratetime) { // get start of each week. $dayofweek = date('w', $liveratetime); $getdate = date('Y-m-d', $liveratetime); $createstart = strtotime('last Sunday', $getdate); $weekstart = ($dayofweek == 0) ? $liveratetime : $createstart; // get the current time interval for a week, i.e. Sunday 00:00:00 UTC $currentInterval = mktime(0,0,0, date('m', $weekstart), date

Convert MMDDYYYY to date for PHP

送分小仙女□ 提交于 2019-12-19 09:48:39
问题 I have a string with a date which is in this format MMDDYYYY (ie. 01132012, 01142012 etc.) I need to do something on a page, if that string is 14 days or less from the current date. ie. Today is 01132012, so any strings with 12312011 or a less date are going to be showing something on a page. Can anyone help with this? I've tried echo date("d/m/Y", strtotime('01142012')); But to no avail. 回答1: You can use the DateTime class of PHP <? // current date $now = new DateTime(); //your date $date =

get strtotime of specific time in php

痴心易碎 提交于 2019-12-19 08:17:59
问题 I want to get the timestamp of a day/time for eg 17/12/2014 8pm Currently I am doing $curtime = strtotime(date("Y-m-d H:i:s")); which is giving me the current timestamp but I need to be of 8pm. Any help is highly appreciated. Thanks in advance. 回答1: If you're trying to get a timestamp of today at 8pm, it's actually much more simple than using date since you can use relative times in a strtotime : $curtime = strtotime('today 8pm'); If you test this with date : echo date('Y-m-d H:i:s', $curtime

PHP时间戳和日期相互转换

吃可爱长大的小学妹 提交于 2019-12-18 20:13:34
在php中我们要把时间戳转换日期可以直接使用date函数来实现,如果要把日期转换成时间戳可以使用strtotime()函数实现,下面我来给大家举例说明。 1.php中时间转换函数 strtotime (date()) date("Y-m-d H:i",$unixtime) 2.php中获得今天零点的时间戳 要获得零点的unix时间戳,可以使用 $todaytime=strtotime(“today”), 然后再使用 date("Y-m-d H:i",$todaytime)转换为日期。 时间戳转换为日期 时间戳转换函数: date("Y-m-d H:i:s",time()),"Y-m-d H:i:s"是转换后的日期格式,time()是获得当前时间的时间戳。如果是date("Y-m-d H:i:s",time()),则小时分秒一起显示;如果是 date("Y-m-d ", time()),只显示年月日。例如: date("Y-m-d H:i:s",time()) 转换后为: 2010-07-18 18:42:48 date("Y-m-d",time()) 转换后为: 2010-07-18 日期转换为时间戳 . class SaonekController extends Controller { public function index Action (){ /*

PHP strtotime incrementing by weekdays

纵然是瞬间 提交于 2019-12-18 20:08:12
问题 Today is Friday, April 17, 2015. In my app, it automatically generated a "due date" for each assignment. It's set to "5 business days". To accomplish this, We use: date('m/d/Y', strtotime("+5 weekdays")); However, today, this output "04/26/2015". Why? That's a sunday. Why doesn't it give me the 24th, which is what I want? DEMO: http://codepad.org/2wvnypOC P.S. After speaking to my boss, we switched to strtotime("+5 days") , but I'm still curious what was wrong with "weekdays" . 回答1: It's a

PHP strtotime() function wrong by 1 hour?

我的未来我决定 提交于 2019-12-18 14:48:14
问题 I am converting dates and times into timestamps using PHP before they are inserted into my MySQL database. My problem is that when i use PHP's strtotime function the output timestamp is -1 hour behind my actual time. For example, considering todays date: 07/21/2010. When i use php code like: <?php $my_timestamp = strtotime("07/21/2010"); echo $my_timestamp; ?> The timestamp sent back is the GMT equivilent MINUS 1 hour. i.e. i get back: 20 Jul 2010 23:00:00 GMT instead of 21 Jul 2010 00:00:00