Android如何格式化时间显示
在开发中,我们可能会遇到数据格式限制的问题,那么怎么样对数字进行格式化显示呢?
例如,有这么一个需求:把音乐的播放时间按照xx:xx 的格式显示
int currentMinute = 1;
int currentSecond = 59;
DecimalFormat decimalFormat = new DecimalFormat("00");
//playTime 输出01:59
String playTime = decimalFormat.format(currentMinute) + decimalFormat.format(currentSecond);
做法:new 一个DecimalFormat类的对象,然后调用format方法即可轻松解决问题