android.text.format.DateFormat “HH” is not recognized like with java.text.SimpleDateFormat

后端 未结 5 1056
挽巷
挽巷 2020-12-15 06:35

When I use the \"HH\" flag in android.text.format.DateFormat, it is interpreted as a literal \"HH\". But when I use java.text.SimpleDateFormat it

5条回答
  •  醉梦人生
    2020-12-15 07:05

    For android.text.format.DateFormat you designate Hour in day as kk like this:

    String dateAndroid = android.text.format.DateFormat.format(
        "dd-MM-yyyy kk:mm:ss", calendar).toString();
    

    For java.text.SimpleDateFormat you designate hour in day as HH.

    H hour in day (0-23)

    Documentation for android.text.format.DateFormat:

    public static final char HOUR_OF_DAY

    This designator indicates the hour of the day in 24 hour format. Example for 3pm: k -> 15 Examples for midnight: k -> 0 kk -> 00

提交回复
热议问题