@Override public LocalDateTime convertTo(LocalDateTime localDateTime, Type<LocalDateTime> type, MappingContext mappingContext) { return LocalDateTime.from(localDateTime);
@Override public LocalDateTime convertFrom(LocalDateTime localDateTime, Type<LocalDateTime> type, MappingContext mappingContext) { return LocalDateTime.from(localDateTime);
@Override public LocalDateTime fromString(String string) { return LocalDateTime.from( LocalDateTimeType.FORMATTER.parse( string ) );
/**
* 把字符串转成日期类型.
* 输入的日期格式:yyyy-MM-dd
* @param str 日期字符串
* @return 转换后的日期
* @throws ParseException 异常
* @see LocalDateTime
public static LocalDateTime parseLocalDateTime10(final String str) throws ParseException {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMAT_DATEONLY);
LocalDateTime time = LocalDateTime.from(LocalDate.parse(str, formatter).atStartOfDay());
return time;
/**
* Converts a string object for an object type of {@link LocalDateTime}.
* If the column definition allows null and default value is 0000-00-00 00:00:00, we need return null,
* else 0000-00-00 00:00:00 will be replaced with 1970-01-01 00:00:00;
* @param column the column definition describing the {@code data} value; never null
* @param value the string object to be converted into a {@link LocalDateTime} type;
* @return the converted value;
private Object convertToLocalDateTime(Column column, String value) {
final boolean matches = EPOCH_EQUIVALENT_TIMESTAMP.matcher(value).matches() || "0".equals(value);
if (matches) {
if (column.isOptional()) {
return null;
value = EPOCH_TIMESTAMP;
return LocalDateTime.from(timestampFormat(column.length()).parse(value));
@Before public void before() { time = 1505892010L; date = new Date(1505892470110L); localDateTime = LocalDateTime.from(Instant.ofEpochSecond(time).atZone(ZoneId.systemDefault()));
/**
* Copy constructor.
* @param entity Entity to copy from.
EntityWithDateTimeFields(EntityWithDateTimeFields entity) {
id = entity.id;
locTime = LocalTime.from(entity.locTime);
locDate = LocalDate.from(entity.locDate);
locDateTime = LocalDateTime.from(entity.locDateTime);
final int w = ta.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
return GregorianCalendar.from(LocalDateTime
.from(ta)
.with(WeekFields.ISO.weekOfYear(), y)
.with(WeekFields.ISO.weekOfWeekBasedYear(), w)
@Override protected LocalDateTime toType(TemporalAccessor temporalAccessor) { return temporalAccessor == null ? null : LocalDateTime.from(temporalAccessor);
assertThat(schemaB.defaultValue()).isEqualTo(isoString);
LocalDateTime localDateTimeC = LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").parse("2018-01-03 00:00:10"));
assertThat(schemaC.defaultValue()).isEqualTo(new java.util.Date(Timestamp.toEpochMillis(localDateTimeC, MySqlValueConverters::adjustTemporal)));
LocalDateTime localDateTimeD = LocalDateTime.from(DateTimeFormatter
.ofPattern("yyyy-MM-dd HH:mm:ss.S").parse("2018-01-03 00:00:10.7"));
assertThat(schemaD.defaultValue()).isEqualTo(new java.util.Date(Timestamp.toEpochMillis(localDateTimeD, MySqlValueConverters::adjustTemporal)));
LocalDateTime localDateTimeE = LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS").parse("2018-01-03 00:00:10.123456"));
assertThat(schemaE.defaultValue()).isEqualTo(new java.util.Date(Timestamp.toEpochMillis(localDateTimeE, MySqlValueConverters::adjustTemporal)));
long toEpochMillis1 = Timestamp.toEpochMillis(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").parse(value2)), MySqlValueConverters::adjustTemporal);
assertThat(schemaC.defaultValue()).isEqualTo(toEpochMillis1);
long toEpochMillis2 = Timestamp.toEpochMillis(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S").parse(value3)), MySqlValueConverters::adjustTemporal);
assertThat(schemaD.defaultValue()).isEqualTo(toEpochMillis2);
long toEpochMicro = MicroTimestamp.toEpochMicros(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS").parse(value4)), MySqlValueConverters::adjustTemporal);
assertThat(schemaE.defaultValue()).isEqualTo(toEpochMicro);
long toEpochMillis1 = Timestamp.toEpochMillis(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").parse(value2)), MySqlValueConverters::adjustTemporal);
assertThat(schemaC.defaultValue()).isEqualTo(toEpochMillis1);
long toEpochMillis2 = Timestamp.toEpochMillis(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S").parse(value3)), MySqlValueConverters::adjustTemporal);
assertThat(schemaD.defaultValue()).isEqualTo(toEpochMillis2);
long toEpochMicro = MicroTimestamp.toEpochMicros(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS").parse(value4)), MySqlValueConverters::adjustTemporal);
assertThat(schemaE.defaultValue()).isEqualTo(toEpochMicro);
long toEpochMillisE = Timestamp.toEpochMillis(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").parse(valueE)), MySqlValueConverters::adjustTemporal);
assertThat(schemaE.defaultValue()).isEqualTo(toEpochMillisE);
LocalDateTime ldt = LocalDateTime.from(temporal);
this.timestamp = OffsetDateTime.of(ldt, offset);
return OffsetDateTime.from(given);
} else {
return OffsetDateTime.of(LocalDateTime.from(given), this.defaultZoneOffset);
public LocalDateTime getDataHoraProcessamento() {
try {
return LocalDateTime.parse(this.dataHoraProcessamento, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"));
} catch (final Exception e) {
return LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX")
.parse(this.dataHoraProcessamento))
.atZone(ZoneId.systemDefault()).toLocalDateTime();
@Override public LocalDateTime read(final String data) { return LocalDateTime.from(CTLocalDateTimeTransformer.DATETIME_FORMATTER.parse(data)) .atZone(ZoneId.systemDefault()).toLocalDateTime();
@Override protected LocalDateTime convert2Target(DateTimeFormatter formatter, String obj) { TemporalAccessor temporal = formatter.parse(obj); try { return LocalDateTime.from(temporal); } catch (DateTimeException ex) { // a local date only string return LocalDate.from(temporal).atStartOfDay();
/**
* Parses the date using the formatter to create
* {@link LocalDateTime} instances.
* @param date The date to parse.
* @param formatter The formatter to use.
public LocalDateTimeOf(final CharSequence date,
final DateTimeFormatter formatter) {
this.parsed = new UncheckedScalar<>(
() -> LocalDateTime.from(formatter.parse(date))
public static SqmLiteralTimestamp from(String literalText, SqmCreationContext creationContext) {
final Timestamp literal = Timestamp.valueOf(
LocalDateTime.from( JdbcTimestampJavaDescriptor.FORMATTER.parse( literalText ) )
return new SqmLiteralTimestamp(
literal,
creationContext.getSessionFactory().getTypeConfiguration().getBasicTypeRegistry().getBasicType( Timestamp.class )