Java Date Time - How to build SpringBoot RestApi - Post/Get request with Java Date Time

Java Date Time - How to build SpringBoot RestApi - Post/Get request with Java Date Time

In the tutorial, we build a SpringBoot RestAPIs example that post/get data with java.util.Date time and save it to MySQL/PostgreSQL database using Spring JPA. Working with Java Date Time is an exciting part but also not easy task, fortunately we have the supporting from utilities of Jackson lib, now the job can be done in … Continue reading "Java Date Time – How to build SpringBoot RestApi – Post/Get request with Java Date Time using Jackson and Make Query with Spring JPA example"

https://grokonez.com/spring-framework/spring-boot/java-date-time-how-to-build-springboot-restapi-post-get-request-with-java-date-time-using-jackson-and-make-query-with-spring-jpa-in-mysql-postgresql-examples

Java Date Time – How to build SpringBoot RestApi – Post/Get request with Java Date Time using Jackson and Make Query with Spring JPA example

[no_toc] In the tutorial, we build a SpringBoot RestAPIs example that post/get data with java.util.Date time and save it to MySQL/PostgreSQL database using Spring JPA. Working with Java Date Time is an exciting part but also not easy task, fortunately we have the supporting from utilities of Jackson lib, now the job can be done in an easy way.

Let's do details by steps!

Format Java Date Time with Jackson

Set the Format with @JsonFormat

With the @JsonFormat annotation of Jackson, we can use it to format a specific field in Java model:

public class DateTimeModel {    

    @JsonFormat(pattern="yyyy-MM-dd")
    private Date date;

    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date datetime;

    ...
}

Set TimeZone with @JsonFormat

For setting Time Zone, we use timezone attribute of the @JsonFormat:

@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone="Europe/Paris")
private Date datetimewithzone;

Set Default Format

We can configure a default format & time-zone for all dates in application.properties:

https://grokonez.com/spring-framework/spring-boot/java-date-time-how-to-build-springboot-restapi-post-get-request-with-java-date-time-using-jackson-and-make-query-with-spring-jpa-in-mysql-postgresql-examples

Java Date Time – How to build SpringBoot RestApi – Post/Get request with Java Date Time using Jackson and Make Query with Spring JPA example

java springboot springjpa restapi

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How to Install OpenJDK 11 on CentOS 8

What is OpenJDK? OpenJDk or Open Java Development Kit is a free, open-source framework of the Java Platform, Standard Edition (or Java SE).

Java Online Training | Java Online Course | ITGuru

Our Java Online Training provide you to learn about Java programming and its different features with realty. Our Java Online Course includes live sessions, live projects

Best Java IDE 2020 | Most Popular Java IDE

Our Java Online Training provide you to learn about Java programming and its different features with realty. Our Java Online Course includes live sessions, live projects

Learning by Doing: How to Learn Java Basics by Building Your Own Project

Check out some ideas for sample projects that can help you learn Java, and programming in general, in a fun and engaging way.

Java Core (2020) | Java for beginners | Brush up your Java Skills | Get Hired

In this video we will learn about all the major concepts that come under Java Core . The course is very carefully designed and is made with keeping simplicit...