SimpleDateFormat How can I query a specific time?

Discussion in 'Spigot Plugin Development' started by nikku, Jan 24, 2020.

  1. Hello, I want a message to come every day at 4pm, how can I do this?

    my code:
    public static void updateTimeBar() {
    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
    final String message = "§7§lcurrent time §a" + simpleDateFormat.format(new Date());
    for (Player p : Bukkit.getOnlinePlayers()) {
    p.sendMessage(message);

    }
    }
    }
    I imagine it like this:
    if(time == 16:00){
    Bukkit.broadcastMessage("ItsTime to fap!");

    how could I implement it like this?
     
  2. Hey,
    you can get the current hour and minute with the following code:

    Code (Java):
    Calendar calendar = Calendar.getInstance();

    int hour = calendar.getTime().getHours();
    int minute = calendar.getTime().getMinutes();

    if (hour == 16 && minute == 0) {
        // do something
    }