计算两个时间戳的差
来源:互联网 发布:台湾淘宝 编辑:程序博客网 时间:2024/04/28 20:03
关键代码如下:
/*获取系统时间 格式为:*/
public void getCurrentDate() {String da=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis());
System.out.println("当前时间是:"+da);
String aa=testD(da);
testDe("1478728906000",aa);
}
//两个时间戳的差
public void testDe(String strtime1,String strtime2) {
long time1=Long.valueOf(strtime1);
long time2=Long.valueOf(strtime2);
long day = 0;
long hour = 0;
long min = 0;
long sec = 0;
long diff ;
String flag;
if(time1<time2) {
diff = time2 - time1;
flag="前";
} else {
diff = time1 - time2;
flag="后";
}
day = diff / (24 * 60 * 60 * 1000);
hour = (diff / (60 * 60 * 1000) - day * 24);
min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
sec = (diff/1000-day*24*60*60-hour*60*60-min*60);
System.out.println(day+"天"+flag+hour+"小时"+flag+min+"分钟"+flag+"刚刚");
// if(day!=0)return day+"天"+flag;
// if(hour!=0)return hour+"小时"+flag;
// if(min!=0)return min+"分钟"+flag;
// return "刚刚";
}
打印结果如下:
当前时间是:2016-11-10 06:12:31
1478729551000
0天前0小时前10分钟前刚刚
0 0
- 计算两个时间戳的差
- php计算两个时间戳的差
- 计算两个时间的差
- 计算两个时间的差
- 计算两个时间的差 年龄计算
- C#中计算两个时间的差
- 计算两个时间之差的函数
- C#中计算两个时间的差
- C#中计算两个时间的差
- C#中计算两个时间的差
- C#中计算两个时间的差
- C#中计算两个时间的差
- C#中计算两个时间的差
- 计算两个时间的日期差
- php 计算两个时间的差
- php计算两个时间之间的差
- PHP计算两个时间戳之差
- 计算两个时间之差
- 电路关键元件讲解
- 第五章 编程练习
- 前端:调试时 导入外部Js到网页
- 第十一章 编译器:代码生成
- kubernetes1.4 基础篇:Learn Kubernetes 1.4 by 6 steps(3):Step 2. Using kubectl to Create a Deployment
- 计算两个时间戳的差
- Knockout <!--ko-->与PartialView
- 百度地图起点与终点的距离计算(有偿求助)
- 勾股定理一日一证连载157
- Maven从零开始_3_Maven依赖
- [Android] AS 中 Gradle 配置运行浅析
- 网易视频云互动直播公测正式启动
- [非旋转Treap 权值线段树] 2016 计蒜之道 初赛 第五场 腾讯的新游戏
- 网易视频云互动直播公测正式启动