Parse string date time value input in Java


In Java, you can parse string date time value input using

SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");

We have used the above class since we imported the following package −

import java.text.SimpleDateFormat;

Now, we can display the date in the same format −

Date dt = (Date) dateFormatter.parseObject("Tue, 20 Nov 2018 16:10:45 -0530");

The following is an example −

Example

 Live Demo

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
   public static void main(String[] argv) throws Exception {
      Format dateFormatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
      Date dt = (Date) dateFormatter.parseObject("Tue, 20 Nov 2018 16:10:45 -0530");
      System.out.println(dt);
   }
}

Output

Tue Nov 20 21:40:45 UTC 2018

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 27-Jun-2020

284 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements