Java Program to Convert String to Date

Object Oriented ProgrammingJava8Java Programming

SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting.

Program

Live Demo

import java.util.*;
import java.text.*;

public class DateDemo {

   public static void main(String args[]) {
      Date dNow = new Date( );
      SimpleDateFormat ft =
      new SimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz");

      System.out.println("Current Date: " + ft.format(dNow));
   }
}

Output

Current Date: Sun 2018.04.22 at 07:14:02 PM UTC
raja
Published on 26-Apr-2018 11:11:05
Advertisements