The conversion of string and Date in Java, the correspondence of time field and JavaBean in mysql

Reference materials:
1. Conversion between string and date (date) formats in java
2. Datetime type field in MySQL and the type corresponding to JavaBean

One, the correspondence between the time field in JavaBean and mysql

Note: The Date package is under util, which is the parent class of other time types under sql.
The situation I tested is like this: The
first situation: when the
database field is datetime and JavaBean is Date, the information can be received. For example: Sun Nov 22 20:13:08 CST 2020
The second case: when the
database field is timestamp and JavaBean is Date, two annotations need to be marked on the Date type if the message cannot be received:

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")

Second, the conversion between String and Date

Summary: Whether it is Date to String or String to Date, the format can be defined at will (single day, single time, date + time)
Date ---------------> Date (due to the need Define the format, so there is this step)
String ---------------> Date (String can be a short time (2007-1-18) or a long time string: yyyy- MM-dd HH:mm:ss)
Date ---------------> String (Date can be a short time or a long time)

See:
[Extract the last day of the month]

Guess you like

Origin blog.csdn.net/weixin_43983411/article/details/109829290