Android时间类格式时间

Mah*_*san 5 java format time android

如何使用Android的Time Class格式化时间.我想以这种格式"hh:mm AM/PM"显示时间.我尝试过使用Time.format函数,但我不确定我是否正确使用它.

谢谢

Nik*_*hil 10

请试试这个..

SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm aa");
Date dt = new Date();
String strValue = timeFormat.format(dt);
Run Code Online (Sandbox Code Playgroud)

  • 我想你的意思是"HH:mm aa" (2认同)
  • 这不回答问题......他说"Android的时间类",你的解决方案使用Java Date! (2认同)

小智 7

Time time = new Time();
time.set(0, 0, 17, 4, 5, 1999);
Log.i("Time", time.format("%d.%m.%Y %H:%M:%S"));
Run Code Online (Sandbox Code Playgroud)