androiddatetimedatetime-format

android string datetime format with month and day


i have like this datetime 09/01/2014 and i want to format this datetime like this 1 september. i wrote some code and i can format this date like this

                        SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");

                        Date _d = df.parse("09/01/2014");                   
                        SimpleDateFormat new_df = new SimpleDateFormat(
                                "dd");
                        String _s = new_df.format(_d);
                        cinemaTime.setStartTime(_s);

in this code result is onlu 01 but i don't know how i can recive 1 september(9th month of years( if anyone knows solution please help me thanks


Solution

  • this method will do the job if you want an output like "1 september 2014".

    public static String dateFormatterforLukka(){       
        String inputDate = "09/01/2014";        
        String inputFormat = "MM/dd/yyyy";
        String outputFormat = "d ' ' MMMM ' ' yyyy";
    
        Date parsed = null;
        String outputDate = "";
        try {
            SimpleDateFormat df_input = new SimpleDateFormat(inputFormat, new Locale("en", "US"));
            SimpleDateFormat df_output = new SimpleDateFormat(outputFormat, new Locale("en", "US"));                    
            parsed = df_input.parse(inputDate);
            outputDate = df_output.format(parsed);
        } catch (Exception e) { 
            outputDate = inputDate;     
        }
        return outputDate;
    }
    

    Read the documentation about: SimpleDateFormat Class