Date help

Discussion in 'Spigot Plugin Development' started by JustCedric, Jun 10, 2016.

  1. Hi guys,

    I've 2 questions, my 1st one is I want to get the current date and the date tomorrow and Im using this code:

    Code (Text):
    DateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy HH:mm:ss");
            Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Europe/Amsterdam"));
            cal.add( Calendar.DATE, 1);
            String convertedDate = dateFormat.format(cal.getTime());
            System.out.println(p.getName() + " has died on " + dateFormat.format(new Date())+ " and tomorrow it's " + convertedDate);
            player.set(UUID + ".die_date", convertedDate);
            Main.getInstance().saveYml(Main.getInstance().playerConfig, Main.getInstance().playerYml);
    Im not getting any errors but I get some weird dates.. Like this is the dateFormat.format(new Date()) 10-48-2016 16:48:58 and this is the date tomorrow 11-48-2016 16:48:58..

    My second question is I'm trying to get if the current date is after the die_date I want to set die_date to null, Im using this code:

    Code (Text):
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Europe/Amsterdam"));
                    Date current = cal.getTime();
                    DateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy HH:mm:ss");
                    if (instance.playerConfig.contains(UUID + ".die_date")) {
                        String death_end = instance.playerConfig.getString(UUID + ".die_date");
                         Date givenDate = null;
                            try {
                                givenDate = dateFormat.parse(death_end);
                            } catch (ParseException e) {
                            Long l = givenDate.getTime();
                            Date end = new Date(l);
                            if (current.after(end)) {
                                instance.playerConfig.set(UUID + ".die_date", null);
                                instance.saveYml(instance.playerConfig, instance.playerYml);
                                System.out.println(p.getName() + " die_date reset");
    but it just gets executed when it's not after the die_date
  2. Yeah dude, i really want to help you but i dont know how.. im not good at math :p

    (Wohoo Amsterdam!!!! The Netherlandss!! Cheeseee!!!)
    • Funny Funny x 1
  3. Does anyone know how to solve this?
  4. Try comparing the time in milliseconds. That's what I use to compare two dates.
  5. And how would I do that exactly?
  6. System.currentTimeMillis()/1000 + i*60 I use this to set the future time, i is the number you would be using, 60 is because i'm only doing minutes.

    then, you just need to compare the system time to that.