Convert string to date then format the date

后端 未结 8 472
我寻月下人不归
我寻月下人不归 2020-12-03 07:52

I am formatting a string to a date using the code

String start_dt = \'2011-01-01\';

DateFormat formatter = new SimpleDateFormat(\"YYYY-MM-DD\"); 
Date date          


        
8条回答
  •  借酒劲吻你
    2020-12-03 08:14

    String myFormat= "yyyy-MM-dd";
    String finalString = "";
    try {
    DateFormat formatter = new SimpleDateFormat("yyyy MMM dd");
    Date date = (Date) formatter .parse("2015 Oct 09");
    SimpleDateFormat newFormat = new SimpleDateFormat(myFormat);
    finalString= newFormat .format(date );
    newDate.setText(finalString);
    } catch (Exception e) {
    
    }
    

提交回复
热议问题