strtotime

strtotime() & date() weird behaviour when converting date in to same format as it was before

谁说胖子不能爱 提交于 2019-12-30 07:10:12
问题 I have to convert date format in to mm-dd-yyyy I don't know what is the current date format it is dynamic so if I have dynamic date format is already in mm-dd-yyyy then date() function is returning below outout $date='02-13-2011'; echo date('m-d-Y',strtotime($date)); output is 01-01-1970 ?> http://codepad.org/AFZ6jel7 So I have to check if the date is already in mm-dd-yyyy then do not apply date formatting. Is there any other way do this? may be passing one other parameter in these functions

解析php时间戳与日期的转换

ぐ巨炮叔叔 提交于 2019-12-30 03:28:02
php中时间戳与日期的转换。 实现功能:获取某个日期的时间戳,或获取某个时间的PHP时间戳。 strtotime能将任何英文文本的日期时间描述解析为Unix时间戳,我们结合mktime()或date()格式化日期时间获取指定的时间戳,实现所需要的日期时间。 strtotime 将任何英文文本的日期时间描述解析为Unix时间戳[将系统时间转化成unix时间戳] 一,获取指定日期的unix时间戳 strtotime(”2009-1-22〃) 示例如下: echo strtotime(”2009-1-22“) 结果:1232553600 说明:返回2009年1月22日0点0分0秒时间戳 二,获取英文文本日期时间 示例如下: 便于比较,使用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)打印昨天此时的PHP时间戳strtotime(”-1 day“) 当前时间:echo date(”Y-m-d H:i:s”,time()) 结果:2009-01-22 09

PHP时间戳和日期相互转换(文字有问题)

孤街醉人 提交于 2019-12-30 03:27:37
在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(){ /*

How to make strtotime parse dates in Australian (i.e. UK) format: dd/mm/yyyy?

北城余情 提交于 2019-12-29 06:47:08
问题 I can't beleive I've never come across this one before. Basically, I'm parsing the text in human-created text documents and one of the fields I need to parse is a date and time. Because I'm in Australia, dates are formatted like dd/mm/yyyy but strtotime only wants to parse it as a US formatted date. Also, exploding by / isn't going to work because, as I mentioned, these documents are hand-typed and some of them take the form of d M yy . I've tried multiple combinations of setlocale but no

strtotime equivalent in .NET

安稳与你 提交于 2019-12-28 06:26:52
问题 Is there an equivalent of PHP's strtotime() function working on .NET Framework. I'm talking about it's capacity to handle strings likes: strtotime(" now ") strtotime("10 September 2000") strtotime(" +1 day ") strtotime(" +1 week ") strtotime(" +1 week 2 days 4 hours 2 seconds ") strtotime(" next Thursday ") strtotime(" last Monday ") Obviously DateTime.Parse() and Convert.ToDateTime() don't do that. The closest I've found is a small class which only handles a few of those: http:/

strtotime equivalent in .NET

房东的猫 提交于 2019-12-28 06:26:03
问题 Is there an equivalent of PHP's strtotime() function working on .NET Framework. I'm talking about it's capacity to handle strings likes: strtotime(" now ") strtotime("10 September 2000") strtotime(" +1 day ") strtotime(" +1 week ") strtotime(" +1 week 2 days 4 hours 2 seconds ") strtotime(" next Thursday ") strtotime(" last Monday ") Obviously DateTime.Parse() and Convert.ToDateTime() don't do that. The closest I've found is a small class which only handles a few of those: http:/

strtotime With Different Languages?

独自空忆成欢 提交于 2019-12-27 12:08:04
问题 Does strtotime only work in the default language on the server? The below code should resolve to august 11, 2005, however it uses the french "aout" instead of the english "aug". Any ideas how to handle this? <?php $date = strtotime('11 aout 05'); echo date('d M Y',$date); ?> 回答1: From the docs Parse about any English textual datetime description into a Unix timestamp Edit: Six years down the road now, and what was meant to be a side-note about why strtotime() was an inappropriate solution for

strtotime With Different Languages?

女生的网名这么多〃 提交于 2019-12-27 12:07:33
问题 Does strtotime only work in the default language on the server? The below code should resolve to august 11, 2005, however it uses the french "aout" instead of the english "aug". Any ideas how to handle this? <?php $date = strtotime('11 aout 05'); echo date('d M Y',$date); ?> 回答1: From the docs Parse about any English textual datetime description into a Unix timestamp Edit: Six years down the road now, and what was meant to be a side-note about why strtotime() was an inappropriate solution for

php check if date is today or greater. but only in this month

对着背影说爱祢 提交于 2019-12-25 04:57:22
问题 I have a list of dates and need to enforce a limit, which is the list to not be older than today but more than 30 days ahead of today. Is possible to modify what I have or do I need to use something like 'time' instead? if so how would I adjust what I have? $date = new DateTime($page->meta_value); if (strtotime($page->meta_value) > time()) { echo '<h2><div class="date-title">'; echo $page->post_title.' - '; echo '</div><div class="date-date">'; echo $date->format('d-m-Y').'<br/>'; echo '</div

Basic PHP timezones conversion

落花浮王杯 提交于 2019-12-25 02:46:56
问题 I have looked at previous questions and nothing seems to fit what I require. I am working on a scheduling system and now the client wants to add timezones. So basically I need to be able to proform an action at a specific date and time. Lets say someone chooses to have an alert at the following date/time: 25-12-2010 13:01:00 + / - their timezone I need to be able to store this in mysql as an unix_timestamp, I have been looking at PHP's DateTime and DateTimeZone but this has confused me more.