I saw Force Java timezone as GMT/UTC
I tried
user.timezone=UTC
in config/application.properties
user.timezone=GMT
In the pom.xml:
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <properties> <spring-boot.run.jvmArguments>-Duser.timezone=UTC</spring-boot.run.jvmArguments> </properties> </configuration> </plugin>
But it prints out
System.out.println(TimeZone.getDefault());
sun.util.calendar.ZoneInfo[id="America/New_York",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]
Spring Boot 1.5.19, Java 8
In order to select our timezone, we have to add the connectionTimeZone property to specify the timezone: spring: datasource: url: jdbc:mysql://localhost:3306/test?connectionTimeZone=UTC username: root password: Also, we can, of course, configure the datasource with Java configuration instead.
In windows, we can set the time zone as discussed using the Control Panel -> Date and Time -> Change Time Zone -> Select your preferred time zone option. After setting the environment variable, we can verify it in our Java program. TimeZone timezone = TimeZone. getDefault(); System.
By default, the JVM reads time zone information from the operating system. This information gets passed to the TimeZone class, which stores the time zone and calculates the daylight saving time. We can call the method getDefault, which will return the time zone where the program is running.
Java For Testers UTC stands for Co-ordinated Universal Time. It is time standard and is commonly used across the world. All timezones are computed comparatively with UTC as offset.
I think you can set your application's timezone on your application level. I think this link will help you. https://www.onlinetutorialspoint.com/spring-boot/how-to-set-spring-boot-settimezone.html
So What you need to do is adding "@PostConstruct" annotation to the main class where "@SpringBootApplication" annotation is located, and add timezone setting method there. Here is an example.
@SpringBootApplication public class HellotimezoneApplication { public static void main(String[] args) { SpringApplication.run(HellotimezoneApplication.class, args); } @PostConstruct public void init(){ // Setting Spring Boot SetTimeZone TimeZone.setDefault(TimeZone.getTimeZone("UTC")); } }
Hope this can help you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With