时间有关
+1s
1、获取当前毫秒数
long t1=System.currentTimeMillis();
2、毫秒数转换为时间
Date date2=new Date();
date2.setTime(t1);
System.err.println(date2);
3、时间格式化
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
String fmDate=simpleDateFormat.format(date2);
System.err.println(fmDate);
4、字符串格式时间获取毫秒数
String sdate = "2018-06-01 06-06-06";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
long time = simpleDateFormat.parse(sdate).getTime();
System.err.println(time);
5、毫秒数的计算
把两个毫秒数差值传进来就可以看见相差多久
原贴:https://blog.csdn.net/sunshinestation/article/details/4568946
public static String formatDuring(long mss) {
long days = mss / (1000 * 60 * 60 * 24);
long hours = (mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
long minutes = (mss % (1000 * 60 * 60)) / (1000 * 60);
long seconds = (mss % (1000 * 60)) / 1000;
return days + " days " + hours + " hours " + minutes + " minutes "
+ seconds + " seconds ";
}