0

I need to set the timezone in my application according to my server timezone. my server timezone in IST= Asia/Kolkatta. In java8, timezone can be set directly in @JsonFormat like this:

@JsonCreator
public SystemDateResponseDTO (@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd",timezone = "CST") @JsonProperty("systemDate") final Date systemDate) 
{
        this.systemDate = systemDate;
}

MY dto class:

@Override
public SystemDateResponseDTO getCurrentSystemDate() {
    Date systemDate = systemVariablesRepository.findOne(MIRUNTIME).getDate();
    ZoneId zoneId = ZoneId.of(mset.getTimeZone());
    LocalDateTime localtDateAndTime = LocalDateTime.now(zoneId);
    ZonedDateTime dateAndTimeInSydney = ZonedDateTime.of(localtDateAndTime, zoneId );
    if (RsWebUtil.isNotNull(systemDate)) {
        return new SystemDateResponseDTO(systemDate, dateAndTimeInSydney);
    } else {
        throw new ProcessingException("System Date not Found");
    }
}

Here the timezone, i dont want to hardcode. So im getting the timezone value from my *.properties in this way:

@JsonCreator
public SystemDateResponseDTO(
                             @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") 
                             @JsonProperty("systemDate") final Date systemDate,
                             @JsonProperty("timeZone") final ZonedDateTime timeZone) {
    this.systemDate = systemDate;
    this.timeZone = timeZone;
    LOGGER.info("######****###Default timezone######****###" + timeZone);
}

My current system date is 07.02.2018 and my postgres DB System date is also 07.02.2018.Server timezone is Asia/kolkatta.

From the DTO iam getting the correct timezone and date that iam sending. But while seeing the application, the date is actually one day before (06.02.2018). My timezone is not taken, or is that is getting overriden somewhere else? Iam using java 8,postgres DB 9.6.1 and Jboss 6.3. I have tried setting the JAVA_OPTS = "-Duser.timezone = IST" directly in my standalone too. But no changes. Could somebody help?

Is there is any way to assign my timeZone value, directly to the @JsonFormat timezone type?

0 Answers0