Saturday, 22 November 2014

Convert yyyy-MM-dd HH:mm:ss.SSS format to date object


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateConversion {
    static Date getDate(String str) throws ParseException{
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        Date date = format.parse(str);
        return date;
    }
    
    public static void main(String args[]) throws ParseException{
        String str = "2013-04-04 04:28:18.000";
        Date date = getDate(str);
        System.out.println(date);
       
    }
}


Output
Thu Apr 04 04:28:18 IST 2013



Previous                                                    Next                                                    Home

No comments:

Post a Comment