转自:https://blog.csdn.net/sinat_32238399/article/details/80512452
后期将持续更新
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.毫秒数计算
/**
* 将毫秒数转为时分秒的形式
* @param 要转换的毫秒数
* @return 该毫秒数转换为 * days * hours * minutes * seconds 后的格式
*/
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 ";
}
/**
*
* @param begin 时间段的开始
* @param end 时间段的结束
* @return 输入的两个Date类型数据之间的时间间格用* days * hours * minutes * seconds的格式展示
*/
public static String formatDuring(Date begin, Date end) {
return formatDuring(end.getTime() - begin.getTime());
}
出处:https://blog.csdn.net/sunshinestation/article/details/4568946
6.时间插入数据库
Date date=new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String fmDate=simpleDateFormat.format(date);