Java date format real simple

后端 未结 4 2021
生来不讨喜
生来不讨喜 2021-01-24 17:09

how would you write te date if i have a date and all i want is the month and the day like this (mm/dd) and then turn the month like this July, 08

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-24 18:05

    Let me see if I understood well.

    You have a date like "07/08" and you want "July, 08"?

    You could try SimpleDateFormat

    import java.text.SimpleDateFormat;
    import java.text.ParseException;
    
    class Test {
        public static void main( String [] args ) throws ParseException  {
    
            SimpleDateFormat in  = new SimpleDateFormat("MM/dd");
            SimpleDateFormat out = new SimpleDateFormat("MMMM, dd");
    
            System.out.println( out.format( in.parse("07/08") ) );
    
            // Verbose 
            //String input = "07/09";           
            //Date  date = in.parse( input );  
            //String output = out.format( date );
            //System.out.println( output );
        }
    }
    

提交回复
热议问题