How to set Spring Boot SetTimeZone - onlinetutorialspoint

PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
JAVAEXCEPTIONSCOLLECTIONSSWINGJDBC
EXCEPTIONS
COLLECTIONS
SWING
JDBC
JAVA 8
SPRING
SPRING BOOT
HIBERNATE
PYTHON
PHP
JQUERY
PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
In this tutorial, I am going to show how to set/change the time zone in spring boot application.
JVM will take the default time zone as the server’s time zone. For example, if the server is running on IST, then the JVM takes the IST time as default.
In Spring boot we can quickly change/set this default timezone using java.util.TimeZone class like below.
package com.onlinetutorialspoint.SpringBoot_Custom_ErrorPage;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.TimeZone;

@SpringBootApplication
public class Application {
  @PostConstruct
  public void init(){
    // Setting Spring Boot SetTimeZone
    TimeZone.setDefault(TimeZone.getTimeZone("IST"));
  }
  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
}

Run Application :
[INFO] --- spring-boot-maven-plugin:1.5.10.RELEASE:run (default-cli) @ SpringBoot_Custom_ErrorPage ---

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v1.5.10.RELEASE)

2018-02-17 20:43:21.353  INFO 10356 --- [           main] c.o.S.Application                        : Starting Application on DESKTOP-RN4SMHT with PID 10356 (E:\work\SpringBoot_Custom
_ErrorPage\target\classes started by Lenovo in E:\work\SpringBoot_Custom_ErrorPage)
2018-02-17 20:43:21.353  INFO 10356 --- [           main] c.o.S.Application                        : No active profile set, falling back to default profiles: default
2018-02-17 20:43:21.462  INFO 10356 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebA
pplicationContext@62f32a29: startup date [Sat Feb 17 20:43:21 IST 2018]; root of context hierarchy
2018-02-17 20:43:24.572  INFO 10356 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)

You can see the updated time zone while running the application above.
Happy Learning 🙂

How to use Spring Boot Random Port
Spring Boot How to change the Tomcat to Jetty Server
How to set Spring boot favicon image
How to Set Spring Boot Custom Banner
MicroServices Spring Boot Eureka Server Example
Spring Boot Environment Properties reading based on activeprofile
How to Create own Spring Boot Error Page
Spring Boot Apache ActiveMq In Memory Example
How to change Spring Boot Tomcat Port Number
SSL Spring Boot HTTPs Enabling Example
External Apache ActiveMQ Spring Boot Example
Spring Boot MongoDB + Spring Data Example
Spring Boot JPA Integration Example
Spring Boot Hibernate Integration Example
Spring Boot FileUpload Ajax Example

How to use Spring Boot Random Port
Spring Boot How to change the Tomcat to Jetty Server
How to set Spring boot favicon image
How to Set Spring Boot Custom Banner
MicroServices Spring Boot Eureka Server Example
Spring Boot Environment Properties reading based on activeprofile
How to Create own Spring Boot Error Page
Spring Boot Apache ActiveMq In Memory Example
How to change Spring Boot Tomcat Port Number
SSL Spring Boot HTTPs Enabling Example
External Apache ActiveMQ Spring Boot Example
Spring Boot MongoDB + Spring Data Example
Spring Boot JPA Integration Example
Spring Boot Hibernate Integration Example
Spring Boot FileUpload Ajax Example
 


Δ
 Spring Boot – Hello World
 Spring Boot – MVC Example
 Spring Boot- Change Context Path
 Spring Boot – Change Tomcat Port Number
 Spring Boot – Change Tomcat to Jetty Server
 Spring Boot – Tomcat session timeout
 Spring Boot – Enable Random Port
 Spring Boot – Properties File
 Spring Boot – Beans Lazy Loading
 Spring Boot – Set Favicon image
 Spring Boot – Set Custom Banner
 Spring Boot – Set Application TimeZone
 Spring Boot – Send Mail
 Spring Boot – FileUpload Ajax
 Spring Boot – Actuator
 Spring Boot – Actuator Database Health Check
 Spring Boot – Swagger
 Spring Boot – Enable CORS
 Spring Boot – External Apache ActiveMQ Setup
 Spring Boot – Inmemory Apache ActiveMq
 Spring Boot – Scheduler Job
 Spring Boot – Exception Handling
 Spring Boot – Hibernate CRUD
 Spring Boot – JPA Integration CRUD
 Spring Boot – JPA DataRest CRUD
 Spring Boot – JdbcTemplate CRUD
 Spring Boot – Multiple Data Sources Config
 Spring Boot – JNDI Configuration
 Spring Boot – H2 Database CRUD
 Spring Boot – MongoDB CRUD
 Spring Boot – Redis Data CRUD
 Spring Boot – MVC Login Form Validation
 Spring Boot – Custom Error Pages
 Spring Boot – iText PDF
 Spring Boot – Enable SSL (HTTPs)
 Spring Boot – Basic Authentication
 Spring Boot – In Memory Basic Authentication
 Spring Boot – Security MySQL Database Integration
 Spring Boot – Redis Cache – Redis Server
 Spring Boot – Hazelcast Cache
 Spring Boot – EhCache
 Spring Boot – Kafka Producer
 Spring Boot – Kafka Consumer
 Spring Boot – Kafka JSON Message to Kafka Topic
 Spring Boot – RabbitMQ Publisher
 Spring Boot – RabbitMQ Consumer
 Spring Boot – SOAP Consumer
 Spring Boot – Soap WebServices
 Spring Boot – Batch Csv to Database
 Spring Boot – Eureka Server
 Spring Boot – MockMvc JUnit
 Spring Boot – Docker Deployment