How to format date and time in Android?

前端 未结 24 1323
面向向阳花
面向向阳花 2020-11-22 00:51

How to format correctly according to the device configuration date and time when having a year, month, day, hour and minute?

24条回答
  •  臣服心动
    2020-11-22 01:09

    Use these two as a class variables:

     public java.text.DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
     private Calendar mDate = null;
    

    And use it like this:

     mDate = Calendar.getInstance();
     mDate.set(year,months,day);                   
     dateFormat.format(mDate.getTime());
    

提交回复
热议问题