Convert datetime into time ago

I need to convert DateTime into the year, month, days, hours, minutes, seconds ago like as yahoo question asked 5week ago, or 1 year ago or 1 month ago, my date is saved in the database like this: 2011-11-30 05:25:50 . Now I want to show like year, month, days, hours, minutes and seconds in PHP like: how much year, how many months , days, hours, minutes, seconds ago, but need only one time unit

将datetime转换为更早的时间

我需要将DateTime转换为年,月,日,小时,分钟,秒前像yahoo问题5周前,或1年前或1个月前,我的日期是像这样保存在数据库中: 2011-11-30 05:25:50 。 现在我想在PHP中显示像年,月,日,小时,分钟和秒这样的数据: how much year, how many months , days, hours, minutes, seconds前,但只需要一个时间单位显示就像是年或几天或几小时或几分钟或几秒钟。 我已经搜索了这个,但不明白我怎么能做到这一点,我知道有关Stack

Calculate passed time with PHP

I got the time difference between dates like this : $time1 = "2013-02-25 12:00:00"; $time2 = "2013-01-01 12:00:00"; $tdiff = strtotime($time1) - strtotime($time2); I want extract days, hours and minutes from $tdiff . Output should like : 35 days 6 hours 14 minutes I really searched and try to do something by myself. But I can't get true value. ---- EDIT ---- I can found date diff. I

用PHP计算传递的时间

我得到这样的日期之间的时间差异: $time1 = "2013-02-25 12:00:00"; $time2 = "2013-01-01 12:00:00"; $tdiff = strtotime($time1) - strtotime($time2); 我想从$tdiff提取天,小时和分钟。 输出应该如下: 35 days 6 hours 14 minutes 我真的搜索并尝试自己做一些事情。 但我无法获得真正的价值。 ----编辑----我可以找到日期差异。 我想从计算时间中提取天数,小时数和分钟数...... ----编辑2 ----这是我完整的mys

Writing a PHP function that converts UK date to relative time

What would be the best way of converting UK date and time in the format: 30/01/2013 13:30:06 which is d/m/YH:i:s in PHP noation to relative time (ie just now, few minutes ago, 30 minutes ago, 3 hours ago, 1 day ago.. and so on). I've seen several tutorials on the subject but they all revolve around creating functions without any clear explanations. I would appreciate some assistance on

编写一个将英国日期转换为相对时间的PHP函数

以英文格式转换英国日期和时间的最佳方式是什么? 30/01/2013 13:30:06 这是d / m / YH:i:在PHP记法中的相对时间(即现在,几分钟前,30分钟前,3小时前,1天前等等)。 我已经看到了关于这个主题的几个教程,但它们都是围绕创建功能而没有任何明确的解释。 我希望就此事提供一些协助。 希望这可以帮助function timeSince($ptime){ $etime = time() - strtotime($ptime); if( $etime < 1 ){

What is the best way to store duration in MySQL

I need to store duration (number of minutes and/or hours and/or days). I have looked at MySQL type, but DATE and TIME types seems to be used to store a specific date in time. Not a duration. I thinking about using a int to store the number of second, and convert it in the PHP for display. You seem to have the answer yourself. You can store the number of milliseconds(or any unit) in the dur

在MySQL中存储持续时间的最佳方式是什么?

我需要存储持续时间(分钟数和/或小时数和/或天数)。 我曾看过MySQL类型,但DATE和TIME类型似乎用于存储特定日期。 不是持续时间。 我考虑使用int来存储秒数,并将其转换为PHP进行显示。 你似乎自己有答案。 您可以将持续时间中的毫秒数(或任何单位)存储为数字,并将其转换为您希望在应用程序中使用的单位。 您可以将该值存储为一个数字。 您可能不一定需要存储它,如果它是从表中已有的数据计算出来的,则可以运行数

.htaccess setting error

I understand I can set error_display within .htaccess file using predefined constants: http://php.net/manual/en/errorfunc.constants.php I am looking for a number that would let me set the error_display to all but disable strict mode, warnings and notices I guess the equivalent of E_ALL | ~E_WARNINGS | ~E_NOTICES | ~E_STRICT ? 根据PHP常量,这相当于:32767&〜2&〜8&〜2048这是30709(根据我

.htaccess设置错误

我知道我可以使用预定义的常量在.htaccess文件中设置error_display:http://php.net/manual/en/errorfunc.constants.php 我正在寻找一个号码,可以让我为所有人设置error_display,但禁用严格模式,警告和通知 我猜相当于E_ALL | 〜E_WARNINGS | 〜E_NOTICES | 〜E_STRICT? 根据PHP常量,这相当于:32767&〜2&〜8&〜2048这是30709(根据我的Windows程序员的计算器) # in your .htaccess file... php_value error_rep

What is $errno in set

set_error_handler callback function accepts 2 mandatory arguments and 3 optional arguments. One of which is $errno (first one). What is its use ? Is it integer representation of E_ALL or E_NOTICE .... ? The $errno contains the level of the error raised, as an integer. I think this example will make it clear (not my code): switch ($errno) { case E_USER_ERROR: echo "<b>M

什么是$ errno集合

set_error_handler回调函数接受2个强制参数和3个可选参数。 其中之一是$ errno(第一个)。 它有什么用途? 是E_ALL或E_NOTICE的整数表示吗? $ errno包含所引发错误的级别,作为整数。 我认为这个例子会说清楚(不是我的代码): switch ($errno) { case E_USER_ERROR: echo "<b>My ERROR</b> [$errno] $errstr<br />n"; echo " Fatal error on line $errline in file $errfil

Showing all errors and warnings

UPDATE 2: I have now removed the following from the .php file: <?php error_reporting( E_ALL ); ?> I have set display_erros in php.ini as follows: display_errors = On error reporting is set to the following in php.ini error_reporting = E_ALL | E_STRICT After restarting apache, I still get no errors/warnings. UPDATE 1: I have changed error_reporting in php.ini from: error_r

显示所有错误和警告

更新2: 我现在从.php文件中删除了以下内容: <?php error_reporting( E_ALL ); ?> 我已经在php.ini中设置了display_erros,如下所示: display_errors = On 错误报告在php.ini中设置为以下内容 error_reporting = E_ALL | E_STRICT 重新启动Apache后,我仍然没有错误/警告。 更新1: 我已经改变了php.ini中的error_reporting来自: error_reporting = E_ALL&〜E_DEPRECATED 至 error_reporting =

PHP Logical Operators precedence affects variable assignment results strangely

$var4 = 123; function fn1($p1) { return array('p1' => 1, 'p2' => 2); } if ($var1 = fn1(1) AND $var4 == 123) { print_r($var1); } if ($var2 = fn1(1) && $var4 == 123) { print_r($var2); } if (($var3 = fn1(1)) && $var4 == 123) { print_r($var3); } If you run this simple script it will output strange results, at least for me!! First output from first if express

PHP逻辑运算符优先级奇怪地影响变量赋值结果

$var4 = 123; function fn1($p1) { return array('p1' => 1, 'p2' => 2); } if ($var1 = fn1(1) AND $var4 == 123) { print_r($var1); } if ($var2 = fn1(1) && $var4 == 123) { print_r($var2); } if (($var3 = fn1(1)) && $var4 == 123) { print_r($var3); } 如果你运行这个简单的脚本,它会输出奇怪的结果,至少对我来说! 从第一个输出,如果表达式将导致从函数返回的数组&赋值

The behaviour of the or operator in PHP

I'm trying to understand the behavior of or operator. Please see the below examples: $e = false || true; var_dump($e); Output is as expected: bool(true); $f = false or true; var_dump($f); Output is as expected: bool(false) . I understood this in a way that the = has a higher precedence than the Or , so that's why the $f is assigned to false . But the below code works quite opposit

PHP中的or运算符的行为

我试图了解or操作员的行为。 请看下面的例子: $e = false || true; var_dump($e); 输出如预期: bool(true); $f = false or true; var_dump($f); 输出如预期: bool(false) 。 我以某种方式理解了这一点,即=具有比Or更高的优先级,所以这就是$f被赋予false 。 但下面的代码与我的想法完全相反。 我认为$foo将被分配到5 ,然后与自身进行比较。 但是$foo只有在$foo被设置的情况下才会被赋值,这意味着它正在检查$foo

What does this mean?

This question already has an answer here: Reference — What does this symbol mean in PHP? 18 answers You are assigning that array value by reference. passing argument through reference (&$) and by $ is that when you pass argument through reference you work on original variable, means if you change it inside your function it's going to be changed outside of it as well, if you pass ar

这是什么意思?

这个问题在这里已经有了答案: 参考 - 这个符号在PHP中的含义是什么? 18个答案 您正在通过引用分配该数组值。 通过引用(&$)和$传递参数是当你通过引用传递参数时,你使用原始变量,意味着如果你在函数内部改变它,它也会在它之外被改变,如果你将参数作为复制,函数创建此变量的副本实例,并在此副本上工作,因此如果在函数中更改它,它将不会在其外部更改 参考:http://www.php.net/manual/en/language.references