Answer the question
In order to leave comments, you need to log in
How to customize Timestamp format?
There is an essence
import java.sql.Timestamp;
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class Car {
@Id
@GeneratedValue
@JsonIgnore
private Long id;
@NotNull(message = "car number can't be null")
@Pattern(regexp="[A-Z0-9\\- ]{4,16}", message = "invalid car number format")
private String carNumber;
private Timestamp timestamp;
}
@Override
public Car saveCar(Car car) {
car.setTimestamp(new Timestamp(System.currentTimeMillis()));
return carRepository.save(car);
}
Answer the question
In order to leave comments, you need to log in
Specify date format for json:
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "[email protected]:mm:ss")
private Date createdDate;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question