# Converting INT to minutes and seconds

Discussion in 'Plugin Development' started by CrazyGuy3000, Oct 2, 2013.

Not open for further replies.
1. Offline

### CrazyGuy3000

Hey guys,
How does one convert time to minutes and seconds using java. I know you need to use math to do this but how do I display its as (12M 30S)? Thanks

#1
2. Offline

Code:
```int minutes = Math.floor(time / 60);
int seconds = time % 60;
```
Like that?

#2
3. Offline

### Loogeh

CrazyGuy3000 Are you converting from milliseconds? If so, this works but there are more units in here than you wanted. You could change it to your liking though.

Code:
```    public static String millisToReadable(long millis, boolean abbreviate) {
int x = (int) (millis / 1000);
int seconds = x % 60;
x /= 60;
int minutes = x % 60;
x /= 60;
int hours = x % 24;
x /= 24;
long days = x % 7;
x /= 7;
long weeks = x;
if(!abbreviate) return weeks + " weeks " + days + " days " + hours + " hours " + minutes + " minutes " + seconds + " seconds";
else return weeks + "w-" + days + "d-" + hours + "h-" + minutes + "m-" + seconds + "s";
}```

#3