0

I Want to convert a date from the format"dd-mmm-yyyy" to "yyyy-mm-dd". And here is my code.

 public void convertDate(){
    GregorianCalendar todaysDate = (GregorianCalendar) month.clone();   // Its show the error over here.
    SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy", Locale.US);
    currentdatestring = df.format(todaysDate.getTime());
    try{
        Date tdate3= df.parse(currentdatestring);
        tdate4=targetDateformat.format(tdate3);
            } 
        catch (ParseException e) {
        Log.e(getPackageName(), e.getMessage());
        e.printStackTrace();
    }   

But the problem is it showing a nullpointer exception . And i am not able to understand the mistake. Please if someone can help ?

4

2 回答 2

0

try this

DateFormat dffrom = new SimpleDateFormat("M/dd/yyyy");
DateFormat dfto = new SimpleDateFormat("yyyy-MM-dd");  
Date today = dffrom.parse("7/1/2011");String s = dfto.format(today);
于 2013-09-04T04:38:09.520 回答
0

Try this :

Date cDate = new Date();
DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = dateFormat.parse(cDate);

Hope it will help you.

于 2013-09-04T04:48:00.843 回答