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
Updated on: 2020-06-27T12:44:32+05:30

347 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements