时间显示函数 经常看见论坛或是微博的发布时间显示为,几秒前,几小时前,今天xx:xx,昨天xx:xx.....应该有什么函数能快捷的计算出来这些吧,写一个觉得很麻烦,网上搜索又不知道怎么描述,所以希望哪个大侠给发一下此函数 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 php没有这样的函数,需要你自己写以前我写过这个功能,就二三十来行代码而已。嫌麻烦还学编程 两天前$nowd = date("Ymd h:i:s");$arr[] = date("Ymd h:i:s",strtotime("-2 day $nowd")); //两秒前$nowd = date("Ymd h:i:s");$arr[] = date("Ymd h:i:s",strtotime("-2 Second $nowd")); $CurrentTime=getdate(); //取得当前时间数组$OldTime=strtotime($rw['lastdate']); //取得存在数据库中时间的Unix时间戳$TimeDifference=$CurrentTime[0]+(8*3600)-$OldTime;//把当前时间的Unix时间戳减去存在数据库中时间的Unix时间戳if($TimeDifference<60) //如果Unix时间戳小于60秒就显示多少秒前发布的{echo floor($TimeDifference)."秒前";}elseif($TimeDifference<3600) //如果Unix时间戳大于60秒小于3600秒就显示多少分钟前发布{$min=$TimeDifference/60; //时间戳差除以60得到多少分钟前echo floor($min)."分钟前"; }else //否则按存在数据库中的格式显示时间{ echo $rw['lastdate'];} $time1 = $rows_arr['products_details_time'];//数据库保存时间 $time2 = date("Y-m-d H:i:s"); $cle = $time2 - $time1; //得出时间戳差值 $d = floor($cle/3600/24); $h = floor(($cle-($d*3600*24))/3600); $m = floor(($cle-($d*3600*24)-($h*3600))/60); $str=''; $str.=$d ? $d.'天' : '' ; $str.=$h ? $h.'小时' : '' ; $str.=$m ? $m.'分钟' : '1分钟' ; echo $str.'前'; 用js语句写啊,能具体到日期星期几呢// JavaScript Documentfunction initArray(){ for(i=0;i<initArray.arguments.length;i++) this[i]=initArray.arguments[i]; } var isnMonths=new initArray("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"); var isnDays=new initArray("星期日","星期一","星期二","星期三","星期四","星期五","星期六","星期日"); today=new Date(); hrs=today.getHours(); min=today.getMinutes(); sec=today.getSeconds(); clckh=""+((hrs>12)?hrs-12:hrs); clckm=((min<10)?"0":"")+min; clcks=((sec<10)?"0":"")+sec; clck=(hrs>=12)?"下午":"上午"; var stnr=""; var ns="0123456789"; var a=""; function getFullYear(d){ //d is a date object yr=d.getYear(); if(yr<1000) yr+=1900; return yr; } document.write(getFullYear(today)+"年"+isnMonths[today.getMonth()]+""+today.getDate()+"日 "+isnDays[today.getDay()]); 日期转换问题 <input type="button" value="<?php echo $bnlanglog_operate_log;?>" class=<?php e PHP邮件函数mb_send_mail(),错误警告 求个带转义符的正则怎么写 各位大虾好!!如何防止网站里的数据文件被别人下载 求一条sql 正则问题,搞不住了 最近想在北京举行php的一次交流会 在mysql中建表时为什么char(6)会变成varchar(6)?怎么改? 通过调用界面跟方法讲三个文件在一个文件处理。。。。 求助,PHP关于数据库连接出错问题 问一个mysql问题.
以前我写过这个功能,就二三十来行代码而已。嫌麻烦还学编程
//两秒前
$nowd = date("Ymd h:i:s");
$arr[] = date("Ymd h:i:s",strtotime("-2 Second $nowd"));
$OldTime=strtotime($rw['lastdate']); //取得存在数据库中时间的Unix时间戳
$TimeDifference=$CurrentTime[0]+(8*3600)-$OldTime;//把当前时间的Unix时间戳减去存在数据库中时间的Unix时间戳
if($TimeDifference<60) //如果Unix时间戳小于60秒就显示多少秒前发布的{
echo floor($TimeDifference)."秒前";
}
elseif($TimeDifference<3600) //如果Unix时间戳大于60秒小于3600秒就显示多少分钟前发布
{
$min=$TimeDifference/60; //时间戳差除以60得到多少分钟前
echo floor($min)."分钟前";
}
else //否则按存在数据库中的格式显示时间
{
echo $rw['lastdate'];
}
$time2 = date("Y-m-d H:i:s");
$cle = $time2 - $time1; //得出时间戳差值
$d = floor($cle/3600/24);
$h = floor(($cle-($d*3600*24))/3600);
$m = floor(($cle-($d*3600*24)-($h*3600))/60);
$str='';
$str.=$d ? $d.'天' : '' ;
$str.=$h ? $h.'小时' : '' ;
$str.=$m ? $m.'分钟' : '1分钟' ; echo $str.'前';
// JavaScript Document
function initArray(){
for(i=0;i<initArray.arguments.length;i++)
this[i]=initArray.arguments[i];
}
var isnMonths=new initArray("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");
var isnDays=new initArray("星期日","星期一","星期二","星期三","星期四","星期五","星期六","星期日");
today=new Date();
hrs=today.getHours();
min=today.getMinutes();
sec=today.getSeconds();
clckh=""+((hrs>12)?hrs-12:hrs);
clckm=((min<10)?"0":"")+min;
clcks=((sec<10)?"0":"")+sec;
clck=(hrs>=12)?"下午":"上午";
var stnr="";
var ns="0123456789";
var a="";
function getFullYear(d){ //d is a date object
yr=d.getYear();
if(yr<1000) yr+=1900;
return yr;
}
document.write(getFullYear(today)+"年"+isnMonths[today.getMonth()]+""+today.getDate()+"日 "+isnDays[today.getDay()]);