【OJ源码分享】友好时间实现
大家都看到在话题中,有些时间是“一分钟前”、“昨天”,“一个月前”之类的时间,这样会显得比较友好。
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 )
# |
|
= |
---|---|---|
南柯 | 2023 | |
cxlove | 1970 | |
vainner | 1763 | |
4 | 1000310428赵成帅 | 1718 |
5 | XiaoWen | 1710 |
6 | 1000380213洪伟焕 | 1701 |
7 | weiben | 1684 |
8 | Jungle.Wei | 1678 |
9 | 1100310131曾翔宇 | 1664 |
10 | hongwh | 1653 |
dfs
21
implementation
19
dp
13
string
11
math
11
big number
10
number theory
9
combinatorics
9
happyoj
5
springboot
4
brute force
4
javascript
3
bfs
3
如梦令
3
greedy
3
蓝桥
3
divide and conquer
2
linux
2
Copilot
2
graph
2
probabilities
2
sortings
2
data structures
2
xor
2
python
1
telnetlib
1
cron
1
题解
1
docker
1
https
1
-
略微有单简单
-
```python
-
大大你好,我是一个小白。
-
-
## 我给了一个带出参的由内存申请的函数,它能够识别函数内没有泄漏,但是需要提醒我调用者有没有释放内存,还是不错。
-
## 我先选择了一段比较简单的代码,发现它给出的解释实际上就是代码本身自注释到的
-
## Table of contents
-
最近遇到一个问题,通过springboot Scheduled定时调度,在启动时就会执行定时任务,导致启动性能较差。
-
方法1:
-
配置文件:
-
$(".tag-layout").html(opt); 动态添加的html会导致jquery监听的事件无法响应到如:
-
### 效果
-
```json
-
解决中文乱码,统一配置utf-8:
-
springboot Thymeleaf前台时间显示少了12小时!
谁能帮帮我,部署了项目但是judge.exe每次运行直接闪退怎么办啊???谢谢谢谢谢谢
看下D:\OJ\log目录下的日志,看下异常退出原因
Bug已修复:https://git.oschina.net/jungle/online-judge/commit/fcbe5669aacfeb7a7d0da780f294a6963aa3bc2a