Android format date to MM-DD-YYYY from Datepicker

后端 未结 10 1779
轻奢々
轻奢々 2020-12-16 11:46

I have a datepicker. My app is pushing a notification. I want to display the date in 01-07-2013 MM-dd-yyyy format. Please check my code below:

 //---Button v         


        
10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-16 12:19

    You can add this code:

    Date d = new Date(year, month, day);
    SimpleDateFormat dateFormatter = new SimpleDateFormat(
                    "MM-dd-yyyy hh:mm");
    strDate = dateFormatter.format(d);
    

    after

    year = calendar.get( Calendar.YEAR );
    month = calendar.get( Calendar.MONTH );
    day = calendar.get( Calendar.DAY_OF_MONTH );
    
    hour = calendar.get( Calendar.HOUR );
    minute = calendar.get( Calendar.MINUTE );
    

    So your strDate will be in format you want (MM-dd-yyyy)

提交回复
热议问题