Niklas Werner
Niklas Werner

Reputation: 21

Type Date initial value

I try to set the initial value of Variable (Type: Date) to "2023-01-04 01:05:30.0". I tried every combination, but I always get an error that the syntax is wrong.

Upvotes: 1

Views: 78

Answers (1)

Benjamin
Benjamin

Reputation: 1

The better (and non-deprecated) approach would be to use LocalDate and turn it into a Date:

LocalDateTime.of(2015, Month.JULY, 29, 19, 30, 40).atZone(ZoneId.systemDefault()).toInstant())

Read up on LocalDate and LocalDateTime as they are extremely useful for date manipulations. Only convert back to Date when all is computed and you need it for the model. See https://www.baeldung.com/java-date-to-localdate-and-localdatetime

Upvotes: 1

Related Questions