获取上周时间段
LocalDate localDate = LocalDate.now();
localDate = localDate.plusDays(-1);
LocalDate startTime = localDate.with(DayOfWeek.MONDAY);
LocalDate endTime = localDate.with(DayOfWeek.SUNDAY);
LocalDate转Date
1)使用ZonedDateTime将LocalDate转换为Instant。
2)使用from()方法从Instant对象获取Date的实例
ZoneId zoneId = ZoneId.systemDefault();
LocalDate localDate = LocalDate.now();
ZonedDateTime zdt = localDate.atStartOfDay(zoneId);
Date date = Date.from(zdt.toInstant());
时间戳转时分秒
export const getTimeValue = (start, end)=>{
var stime =new Date(start).getTime();
var etime = new Date(end).getTime();
var usedTime = etime - stime; //两个时间戳相差的毫秒数
var days=Math.floor(usedTime/(24*3600*1000));
//计算出小时数
var leave1=usedTime%(24*3600*1000); //计算天数后剩余的毫秒数
var hours=Math.floor(leave1/(3600*1000));
//计算相差分钟数
var leave2=leave1%(3600*1000); //计算小时数后剩余的毫秒数
var minutes=Math.floor(leave2/(60*1000));
// var time = days + "天"+hours+"时"+minutes+"分";
var time = days;
return time;
}
带时区的字符串转Date
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd hh:mm:ss zzz yyyy", Locale.ENGLISH);
Date date = sdf.parse(po.getCalibratedTime());
时间加减计算用Calendar
Calendar c = Calendar.getInstance();
c.setTime(getCalibratedDate());
c.add(Calendar.MONTH, getCalibrationPeriod().intValue());
this.dueDate = c.getTime();