Home > Back-end >  Difficult: Set Current TimeZone to @ JsonFormat TimeZone value
Difficult: Set Current TimeZone to @ JsonFormat TimeZone value

Time:09-18

All bosses:

A lot of time using Jackson @ JsonFormat formatting:
@ JsonFormat (pattern="yyyy - MM - dd HH: MM: ss", timezone="GMT + 8")
private Date beginTime;

Owing to GMT + 8 the constants for internationalization,

My methods:
Using the default time zone 1
@ JsonFormat (shape=JsonFormat. Shape. STRING, the pattern="HH: mm", timezone.=JsonFormat DEFAULT_TIMEZONE)
Private Date timeQuantumBegin;

2 configuration objectMapper
The @autowired
Public void configureJackson (ObjectMapper ObjectMapper) {
ObjectMapper. SetTimeZone (TimeZone. GetDefault ());
}

But the effect is short of, sent eight hours, how can I specify timezone for the system time zone?

CodePudding user response:

Which bosses have a way?

CodePudding user response:

Have you ever compared with the system time zone? What is the system time zone setting? May have and synchronize the system time zone

CodePudding user response:

@ Configuration
Public class JacksonObjectMapperConfig {

@ Bean
Public ObjectMapper createObjectMapper () {
ObjectMapper ObjectMapper=new Log4jJsonObjectMapper ();
//change the time zone GMT - ObjectMapper & gt; Default: Shanghai
ObjectMapper. SetTimeZone (TimeZone. GetDefault ());
}
}

CodePudding user response:

Interesting, the building Lord why the intervention of the Json conversion process?
You see, if you don't add JsonFormat, the result of the transformation is a what, there should be a time of time string, that is to say, the default support for internationalization,
You after see you add format conversion result is what, just the time of an east eight area, the key is, the converted string on the inside, not the east eight area this information,
Internationalization, if you want to do so, you can use UTC time format (the 2018-01-22 T09: when 083 z) this time, the time difference with Beijing for eight hours, however, do not have what relation, the system will be based on the Locale TimeZone automatic conversion come back,

CodePudding user response:

Oh, I looked at it and if you do not specify JsonFormat, should be a UTC long integer, not a string, but the long integer, is to support the internationalization, the long integer value into a string of words, (the 2018-01-22 T09: when 083 z) is the form,
  • Related