Reputation: 902
I am having an issue to convert string to date object. While converting it is picking the GMT timezone and getting changed into previous date. I want to ignore the timezone.If the string value is "03/12/2019" then it should the same date irrespective of the timezone.
@DateTimeFormat(pattern = "MM/dd/yyyy") Date startDate
Any Suggestions? Thanks.
Upvotes: 1
Views: 2880
Reputation: 7065
You can solved it by using Jodatime LocalDate (which is without time zone by design):
@DateTimeFormat(iso = ISO.DATE) LocalDate startDate
It can be converted to JDK Date by calling toDate() method.
You can also use for date pattern
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE, pattern = "MM/dd/yyyy")
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.3</version>
</dependency>
Upvotes: 2
Reputation: 1292
Use java.time.LocalDate LocalDate has no Time and therefore has no Timezone
@DateTimeFormat(pattern = "MM/dd/yyyy")
private LocalDate localDate;
Upvotes: 1