Convert String to date in java

 Convert String(yyyy-MM-dd HH:mm:ss ) to date in java
public static Date getCurrentTimeStamp(){
        String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
        DateFormat formatter= new SimpleDateFormat(DATE_FORMAT);
        Calendar c1 = Calendar.getInstance(); // today
        System.out.println("Today is " + formatter.format(c1.getTime()));
        try {
            Date date = (Date)formatter.parse(formatter.format(c1.getTime()));
             System.out.println("Date after converted from string: " + date);
             return date;
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            return null;


Popular posts from this blog

Struts 2 - struts tag with boolean property

Can not connect to git using ssh (Permissions 0644 for '/root/.ssh/id_rsa' are too open.