Getting the current time and date on a 24 hour timescale

前端 未结 3 742

I am having problems getting the current time on a 24 hour timescale. As far as I know, \"HH\" should represent the current hour on a 24 hour timescale, however, for some re

相关标签:
3条回答
  • 2020-12-10 14:17

    You can use SimpleDateFormat to format it the way you like, this works:

    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
    String str = sdf.format(new Date());
    

    Also Android version of docs.

    0 讨论(0)
  • 2020-12-10 14:21

    Try this:

          SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
          String s = sdf.format(new Date());
    
    0 讨论(0)
  • 2020-12-10 14:26

    HH is the format specifier for hour of the day in the 24-hour format (0-23; with an offset of 0) only when you utilize the SimpleDateFormat class for formatting dates.

    You are using the format method of the android.text.format.DateFormat class class, that does not employ this notation; instead it uses the symbol k/kk for displaying hours in the 24-hour format. Therefore, your date format string must be specified in the following manner:

    DateFormat.format("kk:mm:ss 'Uhr', dd. MMM", new Date());
    
    0 讨论(0)
提交回复
热议问题