| | |
| | | import java.util.Date; |
| | | |
| | | public class DateComparisonExample { |
| | | public static void main(String[] args) { |
| | | String stringValue = "2023-10-18 00:20:00 - 2023-10-18 00:21:00"; |
| | | Date startDate = parseDate("2023-10-18 00:19:00"); |
| | | Date endDate = parseDate("2023-10-18 00:21:00"); |
| | | |
| | | boolean isBetween = isStringDateBetween(stringValue, startDate, endDate); |
| | | System.out.println("字符串时间是否在两个 Date 类型之间?" + isBetween); |
| | | } |
| | | |
| | | private static Date parseDate(String dateString) { |
| | | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |