# Solved Miliseconds = Minutes/ seconds

Discussion in 'Plugin Development' started by Giorgio, Oct 14, 2012.

Not open for further replies.
1. Offline

### Giorgio

Hello, i need help chaning Miliseconds to Minutes and Seconds. What i need it for is displaying the method:
Code:Java
`offlineTarget.getLastPlayed();`

but this displaies in miliseconds, how can i change it?

#1
2. Offline

#2
3. Offline

### Giorgio

nala3
This still is confusing for me, the linking just shows me the formats, I think its a bit hard to understand it.

#3
4. Offline

### skore87

Do you know what the Milli in Milliseconds stands for? It's simple math man...

#4
5. Offline

### nala3

The getLastPlayed() method returns the time in milliseconds representing the last date played. If you don't understand how milliseconds can represent a date, it is the time in milliseconds since 1970.

So you get the last time played, create a Date object from it. Then create a SimpleDateFormat object as well. Now, use your simple date format to format the Date object into a string.

#5
6. Offline

### skore87

If you need the date, you can call it like this: new Date(LONG)

#6
7. Offline

### Giorgio

nala3

Thats the thing how do i create a SimpleDateFormat?

#7
8. Offline

Here

#8
9. Offline

### one4me

You could use a simple statement like this to easily print the date the player last played.
Code:
```System.out.println(new Date(offlineTarget.getLastPlayed()));
```
You could also format it however you want with SimpleDataFormat.
Code:
```System.out.println(new SimpleDateFormat("yyyyMMddHHmmss").format(offlineTarget.getLastPlayed()));
```
See this for a better explanation and more examples on how to format the date.

And,
1 second = 1000 milliseconds
1 minute = 60 seconds = 60000 milliseconds
1 hour = 60 minutes = 3600 seconds = 3600000 milliseconds
1 day = 24 hours = 1440 minutes = 86400 seconds = 86400000 milliseconds

so if you wanted how many minutes there are between when the player last played and now you would do:
Code:
```System.out.prtinln(((System.currentTimeMillis() - offlineTarget.getLastPlayed()) / 1000) / 60);
```

#9
kroltan likes this.
10. Offline

### Giorgio

one4me

Thank you for your help. And not giving me a link to get confused on. thanks!

#10
11. Offline

### bergerkiller

Code:
```long totalms = 232322256363;
int ms = (int) (totalms % 1000);
int sec = (int) (totalms % 60000);
int hr = (int) (totalms % 360000);
// etc```

#11