【OJ源码分享】友好时间实现

ACSolo  发布于 6 年前 2324 3 0

大家都看到在话题中,有些时间是“一分钟前”、“昨天”,“一个月前”之类的时间,这样会显得比较友好。

OJ中是这样实现的:

public String getFriendlyDate(Date time){
	if(time == null) return getText("unknown");
	int ct = (int)((System.currentTimeMillis() - time.getTime())/1000);
	if(ct < 3600)
		return Math.max(ct / 60,1) +getText("minutes_before");
	if(ct >= 3600 && ct < 86400)
		return ct / 3600 +getText("hours_before");
	if(ct >= 86400 && ct < 2592000){ //86400 * 30
		int day = ct / 86400 ;	
		if(day>1){
			return day +getText("days_before");	
		}
		return getText("yesterday");			
	}
	if(ct >= 2592000 && ct < 31104000) //86400 * 30
		return ct / 2592000 +getText("months_before");
	return ct / 31104000 + getText("years_before");
}


话题评论 ( 3 )

  • 123456  发布于6 年前 Vote: I like it   0   Vote: I do not like it

    谁能帮帮我,部署了项目但是judge.exe每次运行直接闪退怎么办啊???谢谢谢谢谢谢

  • ACSolo  发布于6 年前 Vote: I like it   0   Vote: I do not like it

    看下D:\OJ\log目录下的日志,看下异常退出原因

  • ACSolo  发布于6 年前 Vote: I like it   0   Vote: I do not like it

    Bug已修复:https://git.oschina.net/jungle/online-judge/commit/fcbe5669aacfeb7a7d0da780f294a6963aa3bc2a