LocalDateTimeUtil.of(date).withDayOfMonth(i)
时间: 2023-12-07 13:39:00 浏览: 113
根据提供的引用内容,我们可以看出`LocalDateTimeUtil.of(date).withDayOfMonth(i)`是一个自定义的方法,它的作用是将传入的`date`转换为`LocalDateTime`对象,并将其日期修改为`i`号。具体实现代码如下:
```java
public static LocalDateTime of(Date date) {
return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
}
public static LocalDateTime of(Date date, ZoneId zone) {
return LocalDateTime.ofInstant(date.toInstant(), zone);
}
public static LocalDateTime ofEpochSecond(long epochSecond, ZoneOffset offset) {
return LocalDateTime.ofInstant(Instant.ofEpochSecond(epochSecond), offset);
}
public static LocalDateTime ofEpochMilli(long epochMilli, ZoneOffset offset) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(epochMilli), offset);
}
public static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second) {
return LocalDateTime.of(year, month, dayOfMonth, hour, minute, second);
}
public static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute) {
return LocalDateTime.of(year, month, dayOfMonth, hour, minute);
}
public static LocalDateTime of(int year, int month, int dayOfMonth) {
return LocalDateTime.of(year, month, dayOfMonth, 0, 0);
}
public static LocalDateTime of(LocalDate date, LocalTime time) {
return LocalDateTime.of(date, time);
}
public static LocalDateTime of(int year, Month month, int dayOfMonth, int hour, int minute, int second) {
return LocalDateTime.of(year, month, dayOfMonth, hour, minute, second);
}
public static LocalDateTime of(int year, Month month, int dayOfMonth, int hour, int minute) {
return LocalDateTime.of(year, month, dayOfMonth, hour, minute);
}
public static LocalDateTime of(int year, Month month, int dayOfMonth) {
return LocalDateTime.of(year, month, dayOfMonth, 0, 0);
}
public static LocalDateTime of(LocalDate date) {
return LocalDateTime.of(date, LocalTime.MIN);
}
public static LocalDateTime of(LocalTime time) {
return LocalDateTime.of(LocalDate.now(), time);
}
public static LocalDateTime of(int year, int dayOfYear, LocalTime time) {
return LocalDateTime.of(LocalDate.ofYearDay(year, dayOfYear), time);
}
public static LocalDateTime ofInstant(Instant instant, ZoneId zone) {
return LocalDateTime.ofInstant(instant, zone);
}
public static LocalDateTime parse(CharSequence text) {
return LocalDateTime.parse(text);
}
public static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter) {
return LocalDateTime.parse(text, formatter);
}
public static String format(LocalDateTime dateTime, String pattern) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
return dateTime.format(formatter);
}
public static String format(LocalDateTime dateTime, DateTimeFormatter formatter) {
return dateTime.format(formatter);
}
public static LocalDateTime now() {
return LocalDateTime.now();
}
public static LocalDateTime now(Clock clock) {
return LocalDateTime.now(clock);
}
public static LocalDateTime now(ZoneId zone) {
return LocalDateTime.now(zone);
}
public static LocalDateTime now(ZoneOffset offset) {
return LocalDateTime.now(offset);
}
public static LocalDateTime plusYears(LocalDateTime dateTime, long years) {
return dateTime.plusYears(years);
}
public static LocalDateTime plusMonths(LocalDateTime dateTime, long months) {
return dateTime.plusMonths(months);
}
public static LocalDateTime plusWeeks(LocalDateTime dateTime, long weeks) {
return dateTime.plusWeeks(weeks);
}
public static LocalDateTime plusDays(LocalDateTime dateTime, long days) {
return dateTime.plusDays(days);
}
public static LocalDateTime plusHours(LocalDateTime dateTime, long hours) {
return dateTime.plusHours(hours);
}
public static LocalDateTime plusMinutes(LocalDateTime dateTime, long minutes) {
return dateTime.plusMinutes(minutes);
}
public static LocalDateTime plusSeconds(LocalDateTime dateTime, long seconds) {
return dateTime.plusSeconds(seconds);
}
public static LocalDateTime plusNanos(LocalDateTime dateTime, long nanos) {
return dateTime.plusNanos(nanos);
}
public static LocalDateTime minusYears(LocalDateTime dateTime, long years) {
return dateTime.minusYears(years);
}
public static LocalDateTime minusMonths(LocalDateTime dateTime, long months) {
return dateTime.minusMonths(months);
}
public static LocalDateTime minusWeeks(LocalDateTime dateTime, long weeks) {
return dateTime.minusWeeks(weeks);
}
public static LocalDateTime minusDays(LocalDateTime dateTime, long days) {
return dateTime.minusDays(days);
}
public static LocalDateTime minusHours(LocalDateTime dateTime, long hours) {
return dateTime.minusHours(hours);
}
public static LocalDateTime minusMinutes(LocalDateTime dateTime, long minutes) {
return dateTime.minusMinutes(minutes);
}
public static LocalDateTime minusSeconds(LocalDateTime dateTime, long seconds) {
return dateTime.minusSeconds(seconds);
}
public static LocalDateTime minusNanos(LocalDateTime dateTime, long nanos) {
return dateTime.minusNanos(nanos);
}
public static long between(LocalDateTime startInclusive, LocalDateTime endExclusive, ChronoUnit unit) {
return unit.between(startInclusive, endExclusive);
}
public static boolean isBefore(LocalDateTime dateTime1, LocalDateTime dateTime2) {
return dateTime1.isBefore(dateTime2);
}
public static boolean isAfter(LocalDateTime dateTime1, LocalDateTime dateTime2) {
return dateTime1.isAfter(dateTime2);
}
public static boolean isEqual(LocalDateTime dateTime1, LocalDateTime dateTime2) {
return dateTime1.isEqual(dateTime2);
}
public static boolean isLeapYear(int year) {
return Year.isLeap(year);
}
public static int getYear(LocalDateTime dateTime) {
return dateTime.getYear();
}
public static Month getMonth(LocalDateTime dateTime) {
return dateTime.getMonth();
}
public static int getMonthValue(LocalDateTime dateTime) {
return dateTime.getMonthValue();
}
public static int getDayOfMonth(LocalDateTime dateTime) {
return dateTime.getDayOfMonth();
}
public static int getDayOfYear(LocalDateTime dateTime) {
return dateTime.getDayOfYear();
}
public static DayOfWeek getDayOfWeek(LocalDateTime dateTime) {
return dateTime.getDayOfWeek();
}
public static int getHour(LocalDateTime dateTime) {
return dateTime.getHour();
}
public static int getMinute(LocalDateTime dateTime) {
return dateTime.getMinute();
}
public static int getSecond(LocalDateTime dateTime) {
return dateTime.getSecond();
}
public static int getNano(LocalDateTime dateTime) {
return dateTime.getNano();
}
public static LocalDate toLocalDate(LocalDateTime dateTime) {
return dateTime.toLocalDate();
}
public static LocalTime toLocalTime(LocalDateTime dateTime) {
return dateTime.toLocalTime();
}
public static Date toDate(LocalDateTime dateTime) {
return Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());
}
public static Date toDate(LocalDateTime dateTime, ZoneId zone) {
return Date.from(dateTime.atZone(zone).toInstant());
}
public static Instant toInstant(LocalDateTime dateTime) {
return dateTime.atZone(ZoneId.systemDefault()).toInstant();
}
public static Instant toInstant(LocalDateTime dateTime, ZoneId zone) {
return dateTime.atZone(zone).toInstant();
}
public static String toString(LocalDateTime dateTime) {
return dateTime.toString();
}
public static String toString(LocalDateTime dateTime, String pattern) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
return dateTime.format(formatter);
}
public static String toString(LocalDateTime dateTime, DateTimeFormatter formatter) {
return dateTime.format(formatter);
}
public static LocalDateTime withYear(LocalDateTime dateTime, int year) {
return dateTime.withYear(year);
}
public static LocalDateTime withMonth(LocalDateTime dateTime, int month) {
return dateTime.withMonth(month);
}
public static LocalDateTime withDayOfMonth(LocalDateTime dateTime, int dayOfMonth) {
return dateTime.withDayOfMonth(dayOfMonth);
}
public static LocalDateTime withDayOfYear(LocalDateTime dateTime, int dayOfYear) {
return dateTime.withDayOfYear(dayOfYear);
}
public static LocalDateTime withHour(LocalDateTime dateTime, int hour) {
return dateTime.withHour(hour);
}
public static LocalDateTime withMinute(LocalDateTime dateTime, int minute) {
return dateTime.withMinute(minute);
}
public static LocalDateTime withSecond(LocalDateTime dateTime, int second) {
return dateTime.withSecond(second);
}
public static LocalDateTime withNano(LocalDateTime dateTime, int nanoOfSecond) {
return dateTime.withNano(nanoOfSecond);
}
public static LocalDateTime with(LocalDateTime dateTime, TemporalAdjuster adjuster) {
return dateTime.with(adjuster);
}
public static LocalDateTime with(LocalDateTime dateTime, TemporalField field, long newValue) {
return dateTime.with(field, newValue);
}
public static LocalDateTime plus(LocalDateTime dateTime, TemporalAmount amountToAdd) {
return dateTime.plus(amountToAdd);
}
public static LocalDateTime plus(LocalDateTime dateTime, long amountToAdd, TemporalUnit unit) {
return dateTime.plus(amountToAdd, unit);
}
public static LocalDateTime minus(LocalDateTime dateTime, TemporalAmount amountToSubtract) {
return dateTime.minus(amountToSubtract);
}
public static LocalDateTime minus(LocalDateTime dateTime, long amountToSubtract, TemporalUnit unit) {
return dateTime.minus(amountToSubtract, unit);
}
public static long until(LocalDateTime dateTime, Temporal endExclusive, TemporalUnit unit) {
return dateTime.until(endExclusive, unit);
}
public static LocalDateTime truncate(LocalDateTime dateTime, TemporalUnit unit) {
return dateTime.truncatedTo(unit);
}
```
因此,`LocalDateTimeUtil.of(date).withDayOfMonth(i)`的作用是将传入的`date`转换为`LocalDateTime`对象,并将其日期修改为`i`号。
阅读全文