开发者

how to roundup minute value?

In my android application i need to roundup tmie value.i.e

I need to convert,like

"05-Aug-2011 12:41 PM" into  "05-Aug-2011 12:40 PM".and
"05-Aug-2011 12:44 PM" into  "05-Aug-2011 12:45 PM".

i.e minutes has roundup.5 minute interval.

Pls give an example..

开发者_如何学编程

Thanks in advance


Date rounded = new Date(Math.round((origDate.getTime() / (1000.0 * 60 * 5))) * (1000 * 60 * 5));


Try:

SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy HH:mm aa");
try {
    System.out.println(sdf.format(
            Math.round(sdf.parse("05-Aug-2011 12:44 PM").getTime()/300000.0)*300000));
} catch (Exception e) {
    e.printStackTrace();
}


the time you get will be in Date or some format.. so say

Long l = date.getMinutes();

then use

    if(l/10<5){
if(l/10>=3){
l = l/10+5;
}
else{
l = (l/10)*10;
}
}

else if(l/10>5)
{
if(l/10>=7){
l = l/10+10;
}
else{
l = (l/10)+5;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜