New file |
| | |
| | | package com.dsh.other.util; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.util.Date; |
| | | |
| | | |
| | | //根据当前传入的时间,返回距离当前时间多少天 |
| | | |
| | | public class StudyTimeUtil { |
| | | private StudyTimeUtil() { |
| | | } |
| | | |
| | | /** |
| | | * 获取两个时间的间隔(秒)Obtain the time difference between two instances (in seconds). |
| | | * |
| | | * @param startDate 开始的时间 |
| | | * @return 返回当前时间与开始时间的相差天数 |
| | | */ |
| | | public static int getDateBetween(Date startDate) throws ParseException { |
| | | Date endDate = new Date(); |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | long startDateTime = dateFormat.parse(dateFormat.format(startDate)).getTime(); |
| | | long endDateTime = dateFormat.parse(dateFormat.format(endDate)).getTime(); |
| | | int days = (int) ((endDateTime - startDateTime) / (1000 * 3600 * 24)); |
| | | return days; |
| | | } |
| | | |
| | | public static Date getStartDate(LocalDateTime localDate) { |
| | | Date date = Date.from(localDate.atZone(ZoneId.systemDefault()).toInstant()); |
| | | return date; |
| | | } |
| | | |
| | | |
| | | } |