# Solved Converting real time into Minecraft time

Discussion in 'Plugin Development' started by baenii, Nov 3, 2019.

Not open for further replies.
1. Offline

### baenii

Hej strangers!

It's me again but with another problem this time, *laugh*.
Im trying to sync the ingame time with the systems time. Strangely the days ingame cycles really fast still so I may canculated wrong. Any ideas? - I don't know what could be wrong with my maths.

Code:
```Date currentDate = new Date();
int currentHoursInSeconds = currentDate.getHours() * 3600;
int currentMinutesInSeconds = currentDate.getMinutes() * 60;

Bukkit.getServer().getWorld("world").setTime((currentHoursInSeconds + currentMinutesInSeconds) * 20);
```

Last edited: Nov 3, 2019
#1
2. Offline

### DerDonut

Time in minecraft goes from 0 to 24000. 0 and 24000 is equal to 6 am. Try to recalculate it

#2
3. Offline

### baenii

Oh wow okay, didn't expect that. I thought it would be easier to convert it.
I actually don't have an idea how to convert. Is it even possible? If yes, could u help me one step further?

#3
4. Offline

### Strahan

Well, if the day is 24000 ticks long, divide by 20 to get seconds - 1200 seconds. There are 86,400 seconds in a real day so the ratio is 72 game seconds to 1 real second. So say you want to get 3 PM. 3 PM is 9 hours into a day, assuming said day starts at 6 AM. 9 * 60 * 60 = 32400 seconds / 72 = 450 game seconds * 20 = 9000 ticks.

To go the other way, if you have an MC time of 17500 for example you take that and divide by 20 to get 875 game seconds * 72 = 63,000 real world seconds / 60 = 1,050 minutes / 60 = 17.5 hours. 6 AM + 17.5 hours = 11:30 PM.

#4
baenii likes this.
5. Offline

### baenii

Well I read your reply a couple of times and thought of how to convert. I'm pretty sure I got it correct now.
As a day in minecraft lasts 24000 ticks, I multiplied the real time hours with 1000. That means 12 noon is now 12000 ticks ingame wich is also exactly the half of the day. But as the day in minecraft starts at 6000 and not at 0, I subracted 6000. That means real Hour * 1000 - 6000 equals will give me the current time ingame. Same with minutes but *10 - 60.

Code:
```Date currentDate = new Date();
int currentHoursConverted = (currentDate.getHours()*1000)-6000;
int currentMinutesConverted = (currentDate.getMinutes()*10)-60;

Bukkit.getServer().getWorld("world").setTime(currentHoursConverted + currentMinutesConverted);
```
Thanks!

#5