Hack Forums
12 Clock? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: General Topics (https://hackforums.net/forumdisplay.php?fid=7)
+--- Forum: Entertainment (https://hackforums.net/forumdisplay.php?fid=446)
+---- Forum: Gaming (https://hackforums.net/forumdisplay.php?fid=65)
+---- Thread: 12 Clock? (/showthread.php?tid=4091732)



12 Clock? - i‎M‎irXa™ - Mar 2, 2014

So I'm trying to make a 12 hour clock for my info window and the closest thing I got so far is:
Code
mc.theWorld.getWorldTime()

Which that just gives me how many nanoseconds or milliseconds have passed in the world like "11947" and I have no idea how to convert that into something like "09:22AM".

Anyone got any hints or know where to look?


* - SIM-1576816 - Mar 2, 2014

Java has class called Data, used like "Data date = new Date();" And then you can draw a string with date.get...


* - rogе - Mar 2, 2014

What does this have to do with griefing? This is more of a Java or just Minecraft related thing.


* - Jordin‌ - Mar 2, 2014

I think OP is wanting the time in mine craft, not the time in real life.


* - Spectro_Shifter - Mar 2, 2014

The time in world is different to the time in real life, I believe. Use this for the date:
new Date()
Edit: if you want time in game I think you should divide the ticks by 20 to get the amount of time in seconds. The time is in ticks, I think, not in milliseconds nor nanoseconds.


* - i‎M‎irXa™ - Mar 3, 2014

So I figured it out, not sure if anybody wants it but its here if they do, it has three formats (First one is best) but are all basically "HH:MM:AM/PM". Variables "hour24" and "minute" are from this thread on minecraftforums.net.
Code
    public String getTime(long time){
        int hour24 = ((int)(time / 1000) + 6) % 24; //From MinecraftForums.net
        int hour12 = hour24 <= 11 ? hour24 : hour24 / 2;
        hour12 = hour12 == 0 ? 12 : hour12;
        int minute = (int)((time % 1000 * 60 / 1000)); //From MinecraftForums.net
        String ampm = hour24 <= 11 ? "AM" : "PM";

        return hour12 + ":" + (minute <= 9 ? "0" + minute : minute) + ampm; //Format one
        //return (hour12 <= 9 ? "0" + hour12 : hour12) + ":" + minute + ampm; //Format two
        //return (hour12 <= 9 ? "0" + hour12 : hour12) + ":" + (minute <= 9 ? "0" + minute : minute) + ampm; //Format three
    }
If you cant figure it out how to use it, you use it like this:
Code
getTime(mc.theWorld.getWorldTime);