Long和Date数据类型之间相互转换代码 - 调整时间推前往后,截取long型日期方法。

时间:2021-09-23 05:57:08
SimpleDateFormat DATETIME_SEC_STR = new SimpleDateFormat("yyyyMMddHHmmss");
SimpleDateFormat DATE_STR = new SimpleDateFormat("yyyyMMdd"); Date busyTime = DATE_STR.parse("20150413");
GregorianCalendar currGcTime15Minute = new GregorianCalendar();
currGcTime15Minute.setTime(busyTime);
//当前时间往前推15分钟
currGcTime15Minute.add(Calendar.MINUTE, -15);
//转换成yyyyMMddHHmmss格式的long型
long diff15Minute2 = Long.valueOf(DATETIME_SEC_STR.format(currGcTime15Minute.getTime()));
System.out.println("diff15Minute2="+diff15Minute2); //分析long数据为yyyyMMdd 或者 HHmmss
long yyyyMMdd = 20150411103000l / 1000000;
long HHmmss = 20150411103000l % 1000000;
System.out.println("年月日=" + yyyyMMdd);
System.out.println("时分秒=" + HHmmss);