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;
        }
      
      }

Comments

Popular posts from this blog

Struts 2 : Warning :No configuration found for the specified action: 'Login.action' in namespace: '/'

Upload csv file at Google Cloud Storage using java

Read Images from a xlsx file using Apache POI