php输出指定时间以前时间格式的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了php输出指定时间以前时间格式的方法。分享给大家供大家参考。具体分析如下:

比如说你需要在php中输出3天前,20分钟以前,可以参考下面的代码

function ago($time) {
 $time = strtotime($time);
 $delta = time() - $time;
 if ($delta < 60) {
  return 'less than a minute ago.';
 } else if ($delta < 120) {
  return 'about a minute ago.';
 } else if ($delta < (45 * 60)) {
  return floor($delta / 60) . ' minutes ago.';
 } else if ($delta < (90 * 60)) {
  return 'about an hour ago.';
 } else if ($delta < (24 * 60 * 60)) {
  return 'about ' . floor($delta / 3600) . ' hour(s) ago.';
 } else if ($delta < (48 * 60 * 60)) {
  return '1 day ago.';
 } else {
  return floor($delta / 86400) . ' days ago.';
 }
}

希望本文所述对大家的php程序设计有所帮助。

相关文章

PHP中用header图片地址 简单隐藏图片源地址

复制代码 代码如下:<?php        $path=$_GET["path"];  ...

PHP 源代码分析 Zend HashTable详解第1/3页

HashTable在通常的数据结构教材中也称作散列表,哈希表。其基本原理比较简单(如果你对其不熟悉,请查阅随便一本数据结构教材或在网上搜索),但PHP的实现有其独特的地方。理解了Hash...

PHP简洁函数(PHP简单明了函数语法)

1、与mysql相关 mysql_connect 建立一个与MySQL服务器的连接 语法 resource mysql_connect(string server[,string usi...

10条php编程小技巧

1、写程序的时候会用到这种情况,比如对一个数字进行四舍五入取整。很多人会这样写: 复制代码 代码如下: input a if a - int(a) >= 0.5 then a =&...

apache+codeigniter 通过.htcaccess做动态二级域名解析

复制代码 代码如下: AuthName "yousite Website Coming Soon..." //如果你想给你的网站加个权限访问 AuthType Basic AuthUse...