[英]DateTimeFormat annotation in spring time zone issue
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.
转换它的同时选择GMT时区并将其更改为上一个日期。 I want to ignore the timezone.If the string value is "03/12/2019" then it should the same date irrespective of the timezone.
我想忽略时区。如果字符串值是“03/12/2019”那么它应该是相同的日期而不管时区。
@DateTimeFormat(pattern = "MM/dd/yyyy") Date startDate
Any Suggestions? 有什么建议么? Thanks.
谢谢。
使用java.time.LocalDate而不是Date。
Use java.time.LocalDate LocalDate has no Time and therefore has no Timezone 使用java.time.LocalDate LocalDate没有Time,因此没有Timezone
@DateTimeFormat(pattern = "MM/dd/yyyy")
private LocalDate localDate;
You can solved it by using Jodatime LocalDate (which is without time zone by design): 您可以使用Jodatime LocalDate (没有时区设计)解决它:
@DateTimeFormat(iso = ISO.DATE) LocalDate startDate
It can be converted to JDK Date by calling toDate() method . 它可以通过调用toDate()方法转换为JDK Date。
You can also use for date pattern 您还可以使用日期模式
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE, pattern = "MM/dd/yyyy")
Dependency for maven : 对maven的依赖 :
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.3</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.