How to format date and time in Android?

前端 未结 24 1648
面向向阳花
面向向阳花 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:14

    Here is the simplest way:

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a", Locale.US);
    
        String time = df.format(new Date());
    

    and If you are looking for patterns, check this https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

提交回复
热议问题