Working with time

Discussion in 'Plugin Development' started by slater96, Nov 1, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    slater96

    Hello,

    I need a way to subtract and check the current time against another time for example, an event on the server runs at 16:00, how do I make it so I can say something like 'An event will begin in 4 hours' or minutes or whatever, so it will send a message when it is 12:00 in that case. Hopefully you understand :p

    Thanks.
     
  2. Offline

    CubieX

    Have a look at Calendar.HOUR_OF_DAY and Calendar.MINUTE in the java docs of Oracle.
    And the Calendar class in general.
    Maybe System.currentTimeMillis() will also help. It will give an absolute timestamp of the current time in milliseconds.
     
  3. Offline

    slater96

    CubieX
    Code:
            SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
            Calendar currentTime = Calendar.getInstance();
            if (currentTime.add(Calendar.HOUR_OF_DAY, - 1 == otherTime) {
                         
            }
    I've had a look at it, but the otherTime is a string like '14:30:00' and I've tried converting it to a Date but it won't work. Any ideas?
     
  4. Offline

    slater96

    Can anyone else help me please?
     
Thread Status:
Not open for further replies.

Share This Page