I'm having a bit of trouble with JAva, but I'm following the instructions I find in this site (StackOverflow) to manage Dates in Java.
Basically, I'm parsing a string into a Date, simple stuff, however, I'm getting strange results.
Here's a simplified version of my code
package co.mil.fac.cetad.audit;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
@SpringBootApplication
public class AuditApplication {
public static void main(String[] args) {
SpringApplication.run(AuditApplication.class, args);
}
@Bean
public CommandLineRunner run() throws Exception {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
SimpleDateFormat changeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSXXX");
return (args -> {
TimeZone test = TimeZone.getDefault();
String timestamp = "2020-04-11T14:52:34.8121672+00:00";
Date timestampParsed = changeFormat.parse(timestamp);
});
}
}
The problem is that I'm getting the following result:
- Expected result:
Sat Apr 11 14:52:34 UTC 2020
- Observed result:
Sat Apr 11 17:07:55 UTC 2020
for some strange reason it added 2 hours and 15 minutes to my dates.
Any ideas of what might be happening?