如何将一个时间转换成单独的时分秒的形式,并取出来呢?
下面请看代码:
获得一个时间,例如当前时间:longmCurrentTime = System.currentTimeMillis();
然后是几个重要的方法:
/*
*获得天数
*/
private int getCurrentDays(long timeDistance){
return (int) (timeDistance/(24*60*60*1000));
}
/*
*获得小时数
*/
private int getCurrentHour(long timeDistance){
int hour = (int)(timeDistance%(24*60*60*1000))/(60*60*1000);
return hour;
}
/*
*获得分钟数
*/
private int getCurrentMinute(long timeDistance){
int minute = 0;
minute = (int)(timeDistance%(24*60*60*1000))%(60*60*1000)/(60*1000);
return minute;
}
/*
*获得秒钟数
*/
private int getCurrentMills(long timeDistance){
int mills = (int)(timeDistance%(24*60*60*1000))%(60*60*1000)%(60*1000)/1000;
return mills;
}
之下来可以如此调用:
int days =getCurrentDays(mCurrentTime);
inthour =getCurrentHour(mCurrentTime);
intminute =getCurrentMinute(mCurrentTime);
intmills =getCurrentMills(mCurrentTime);
String mCurrentTimeStr = "现在:"+days+"天"+
hour+"小时"+
minute+"分"+
mills+"秒";