如下 很简单
package tv.kuapp.bobby.pc.util{ public class RelativeTimeUtil { //两种格式的timestamp都可以处理。Sun Oct 24 20:07:33 +0000 2010 格式 和1337301360 格式 // public var myRelativeTime:String = timestampToRelative("Sun Oct 24 20:07:33 +0000 2010"); public static function timestampToRelative(timestamp:Number):String { //--Parse the timestamp as a Date object--\\ var pastDate:Date = new Date(timestamp*1000);//乘1000是因为timestamp是秒数,而这里参数需要毫秒数 //--Get the current data in the same format--\\ var currentDate:Date = new Date();//毫米数 //--seconds inbetween the current date and the past date--\\ var secondDiff:Number = (currentDate.getTime() - pastDate.getTime())/1000; //--Return the relative equavalent time--\\ switch (true) { case secondDiff < 60 : return int(secondDiff) + '秒前'; break; case secondDiff < 120 : return '1分钟前'; break; case secondDiff < 3600 : return int(secondDiff / 60) + '分钟前'; break; case secondDiff < 86400 : return int(secondDiff / 3600) + '小时前'; break; case secondDiff < 172800 : return '昨天'; break; case secondDiff < 2592000: return int(secondDiff / 86400) + '天前'; break; default : return int(secondDiff / 2592000) + '月前'; break; }} } }