简体   繁体   中英

how to roundup minute value?

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

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".

ie 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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM