惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - chinaifne

微软Windows10LTSC2019官方三月更新版镜像 dedecms 5.7sp2 20170405运行PHP7.1的大坑(dedecms PHP7.1) 织梦dedecms移动版设置二级域名的方法 织梦如何设置m.开头的域名 - chinaifne JS前端开发判断是否是手机端并跳转操作(小结) 织梦后台进去后其他菜单点了后没有反应怎么办? 织梦dedecms安全设置详情 百度地图api 标注的图标不显示问题 时时获得高德地图坐标 http://lbs.amap.com/console/show/picker - chinaifne 去掉淘宝微淘主页 操作使用的常见的问题集合 http://bbs.ecshop.com/thread-95341-1-1.html css中font-family的中文字体 Mydomain操作说明 提高新闻采集效率:如何通过google快讯采集新闻 http://www.cnblogs.com/fengyin/archive/2011/01/18/1938628.html 前端优化 http://hi.baidu.com/suofang/home这个兄弟的博客中一些不错的前羰优化工具,今天看不完,改天接着看 iframe中子父窗口互调的js方法 Struts中出现DispatchMapping[***] does not define a handler property 的解决办法 checkstyle配置文件说明 MyEclipse 不编译了,无论怎么更改保存, classes目录下都是空的.
Java中计算时间差
chinaifne · 2011-03-15 · via 博客园 - chinaifne

现在是2004-03-26 13:31:40
过去是:2004-01-02 11:30:24
要获得两个日期差,差的形式为:XX天XX小时XX分XX秒

方法一:
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

try
{
    Date d1 = df.parse("2004-03-26 13:31:40");
    Date d2 = df.parse("2004-01-02 11:30:24");
    long diff = d1.getTime() - d2.getTime();
    long days = diff / (1000 * 60 * 60 * 24);
}
catch (Exception e)
{
}

方法二:
   SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   java.util.Date now = df.parse("2004-03-26 13:31:40");
   java.util.Date date=df.parse("2004-01-02 11:30:24");
   long l=now.getTime()-date.getTime();
   long day=l/(24*60*60*1000);
   long hour=(l/(60*60*1000)-day*24);
   long min=((l/(60*1000))-day*24*60-hour*60);
   long s=(l/1000-day*24*60*60-hour*60*60-min*60);
   System.out.println(""+day+"天"+hour+"小时"+min+"分"+s+"秒");

方法三:
   SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   java.util.Date begin=dfs.parse("2004-01-02 11:30:24");
   java.util.Date end = dfs.parse("2004-03-26 13:31:40");
   long between=(end.getTime()-begin.getTime())/1000;//除以1000是为了转换成秒

   long day1=between/(24*3600);
   long hour1=between%(24*3600)/3600;
   long minute1=between%3600/60;
   long second1=between%60/60;
   System.out.println(""+day1+"天"+hour1+"小时"+minute1+"分"+second1+"秒");