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
            e.printStackTrace();
            return null;
        }
      
      }

Popular posts from this blog

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

Upload file on Google cloud storage using Java servlet on google app engine

Session timeout interceptor in struts 2