最新消息:

PHP函数第24款:将时间转换为距离现在的精确时间FloorTime

PHP扩展函数 杨红伟 4535浏览 0评论

一:函数简介

有时候,我们做下订单,或者前一段时间发生的事情,总会说几天前,几小时前发生的事情,我们用这款函数,轻松地就达到了这个目的,信不信由你,且看下边的示例。

演示地址: http://www.ijquery.cn/phpfunction/FloorTime/demo1.php

下载地址: http://www.ijquery.cn/phpfunction/FloorTime/FllorTime.zip

二:函数应用

echo FloorTime(36000);

返回的结果是:

10小时前

三:函数源代码

<?php
/**
 *  将时间转换为距离现在的精确时间
 *
 * @param     int   $seconds  秒数
 * @return    string
 */
if (!function_exists('FloorTime')) {
	function FloorTime($seconds) {
		$times = '';
		$days = floor(($seconds / 86400) % 30);
		$hours = floor(($seconds / 3600) % 24);
		$minutes = floor(($seconds / 60) % 60);
		$seconds = floor($seconds % 60);
		if ($seconds >= 1)
			$times .= $seconds . '秒';
		if ($minutes >= 1)
			$times = $minutes . '分钟 ' . $times;
		if ($hours >= 1)
			$times = $hours . '小时 ' . $times;
		if ($days >= 1)
			$times = $days . '天';
		if ($days > 30)
			return false;
		$times .= '前';
		return str_replace(" ", '', $times);
	}

}


Warning: Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in /www/wwwroot/www.ijquery.cn/wp-content/themes/d8-3.0/comments.php on line 17
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址