DEV Community

loizenai
loizenai

Posted on

How to use @DateTimeFormat to format Date Time request param in SpringBoot RestAPI Examples

https://ozenero.com/how-to-use-datetimeformat-to-format-date-time-request-param-in-springboot-restapi-examples

How to use @DateTimeFormat to format Date Time request param in SpringBoot RestAPI Examples

[no_toc]
In the tutorial, we show how to work with DateTime request param in SpringBoot RestAPI using @DateTimeFormat.

@DateTimeFormat with DateTime Request Param

@DateTimeFormat is used to declare a field or method parameter should be formatted as a date or time.

We can use @DateTimeFormat with ISO date time pattern, or custom format pattern string:

  • Common ISO enum value: DATE, TIME, DATE_TIME
    • DATE: yyyy-MM-dd, example 2019-03-28
    • TIME: HH:mm:ss.SSSXXX, example 01:30:00.000-05:00
    • DATE_TIME: yyyy-MM-dd'T'HH:mm:ss.SSSXXX, example 2019-03-28T01:30:00.000+07:00

Example @DateTimeFormat with @RequestParam in Spring RestAPI:

More at:

https://ozenero.com/how-to-use-datetimeformat-to-format-date-time-request-param-in-springboot-restapi-examples

How to use @DateTimeFormat to format Date Time request param in SpringBoot RestAPI Examples

Top comments (0)