How do I change date time format in Android?

前端 未结 10 1876
故里飘歌
故里飘歌 2020-11-29 07:19

I am displaying the date and time in Android with this format:
2013-06-18 12:41:24

How can I change it to the following format?
18-j

10条回答
  •  春和景丽
    2020-11-29 08:00

    We can use this format for convert the date. Pass the date as parameter

      public String formatdate(String fdate)
    {
        String datetime=null;
        DateFormat inputFormat = new SimpleDateFormat("dd-MM-yyyy");
        SimpleDateFormat d= new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date convertedDate = inputFormat.parse(fdate);
            datetime = d.format(convertedDate);
    
        }catch (ParseException e)
        {
    
        }
        return  datetime;
    
    
    }
    

提交回复
热议问题