施工人员补卡记录、请假记录相关接口
This commit is contained in:
@ -8,6 +8,7 @@ import java.lang.management.ManagementFactory;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -284,4 +285,28 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将包含年月日的 Date 对象和时分秒字符串合并生成一个新的 Date 对象
|
||||
*
|
||||
* @param date 仅包含年月日部分的 Date 对象(时分秒默认为 00:00:00)
|
||||
* @param timeStr 时分秒字符串,格式为 "HH:mm:ss"(例如 "15:00:00")
|
||||
* @return 合并后的包含日期和时间的 Date 对象
|
||||
*/
|
||||
public static Date combineDateAndTime(Date date, String timeStr) {
|
||||
// 转换 Date 为 LocalDate(系统默认时区)
|
||||
Instant dateInstant = date.toInstant();
|
||||
LocalDate localDate = dateInstant.atZone(ZoneId.systemDefault()).toLocalDate();
|
||||
|
||||
// 使用指定格式解析时间字符串为 LocalTime
|
||||
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||
LocalTime localTime = LocalTime.parse(timeStr, timeFormatter);
|
||||
|
||||
// 合并 LocalDate 和 LocalTime 成 LocalDateTime
|
||||
LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
|
||||
|
||||
// 将 LocalDateTime 转换为 Instant,再转换为 Date
|
||||
Instant combinedInstant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
|
||||
return Date.from(combinedInstant);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user