Search code examples
javalogic

Need DateTimeFormatter for pattern 2011-05-08T07:33:00.000+05:30 in java


what would be the DateTime formatter look for this DateTime format 2011-05-08T07:33:00.000+05:30 formatter in java?

want to build a datetime formatter for 2011-05-08T07:33:00.000+05:30 pattern

Thanks!


Solution

  • You do not need a custom DateTimeFormatter to parse 2011-05-08T07:33:00.000+05:30 as it is already in the default pattern used by OffsetDateTime. Note that the modern date-time API is based on ISO 8601.

    Demo:

    import java.time.OffsetDateTime;
    
    public class Main {
        public static void main(String[] args) {
            OffsetDateTime odt = OffsetDateTime.parse("2011-05-08T07:33:00.000+05:30");
            System.out.println(odt);
        }
    }
    

    Output:

    2011-05-08T07:33+05:30
    

    Learn more about the the modern date-time API from Trail: Date Time.