I use the Volley library, I get the date from the server as a string

 "RecievedDate" : "2017-08-10T10:50:13.217", 

Immediately do the pars like this

 @JsonProperty("RecievedDate") private Date mReceivedDate = new Date(); 

And when I check in debager, this date looks like this

 Thu Aug 10 13:41:12 GMT+03:00 2017 

Here you can see that for some unknown reason this number of hours was added GMT+03:00 , I get 10 hours from the server, after Parsa I have 13 ...

Tell me how to do it so that if I get 10, then after the Parsa, there were also 10 ...

  • one
    The date comes without specifying the timezone, so the parser considers it as UTC. And in the debugger you see the date in your local time zone. Probably you need to write a custom deserializer in which you specify the local timezone for the coming date. - eugeneek

1 answer 1

In the end, decided like this

 final Date currentTime = new Date(); final SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy hh:mm:ss az"); // Give it to me in GMT time. sdf.setTimeZone(TimeZone.getTimeZone("GMT")); System.out.println("GMT time: " + sdf.format(currentTime)); 

Thanks @Edwin Buck

And here is the link

https://stackoverflow.com/questions/5236052/get-gmt-time-in-java

  • With this approach there will be inconsistencies if your application runs on a device with a different timezone. It is better to explicitly indicate in the deserializer of your parser in which timezone the date comes. - eugeneek