com.github.andyshao.time.LocalDateOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Gear Show documentation
Show all versions of Gear Show documentation
Enhance and formating the coding of JDK
The newest version!
package com.github.andyshao.time;
import com.github.andyshao.lang.Convert;
import com.github.andyshao.util.stream.Pair;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.Date;
/**
*
* Title:
* Descript:
* Copyright: Copryright(c) Jan 1, 2016
* Encoding:UNIX UTF-8
* @author Andy.Shao
*
*/
public final class LocalDateOperation {
private LocalDateOperation() {}
/**default convert*/
public static final Convert DEFAULT_CONVERT_TO_DATE = ld -> Date.from(ld.atStartOfDay(ZoneId.systemDefault()).toInstant());
/**
* to date
* @param zoneId {@link ZoneId}
* @return to data {@link Convert}
*/
public static final Convert toDate(ZoneId zoneId){
return ld -> Date.from(ld.atStartOfDay(zoneId).toInstant());
}
/**
* to data
* @return to date {@link Convert}
*/
public static final Convert toDate(){
return DEFAULT_CONVERT_TO_DATE;
}
/**
* to local date
* @return to local date {@link Convert}
*/
public static final Convert, LocalDate> toLocalDate() {
return pair -> {
TemporalAccessor date = pair.getFirstOrDefault(DateTimeFormatter.ofPattern("yyyyMMdd"))
.parse(pair.getSecond());
return LocalDate.from(date);
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy