Solved convert string to date

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

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


    & one more time: Hej!

    I am trying to get a string off the config, convert it into a date, format it and "output" it.
    I now tried different things but neither worked for me. Im always getting an error code which says
    Caused by: java.time.format.DateTimeParseException: Text 'Sun Nov 03 22:15:29 CET 2019' could not be parsed at index 0

    My last try:
    String expirationDateRawString = Main.getInstance().getConfig().getString("Muted Players." + p.getName());
    ZonedDateTime expirationDateRaw = ZonedDateTime.parse(expirationDateRawString);
    SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
    String expirationDate = format.format(expirationDateRaw);
    p.sendMessage(Main.issueprefix + "Du bist aus dem Chat gemuted. Gemuted bis: ┬že" + expirationDate);
  2. Offline


    Last edited: Nov 3, 2019
  3. Offline

    timtower Moderator Moderator

    @baenii Why not use System.currentMillis ?
    Then you don't need to parse it.
  4. Offline


    That's what I used but I need to compare that one to the current date to check if the player is still muted or not.
  5. Offline


    On mute -> save the currenttimemillis
    When you check if the player is muted -> if the new currenttimemillis minus the millis from the mute time is larger than the mute time -> the mute has expired
  6. Offline


    Oh well yeah... I thought I did it that way but I saved the time stamp and not the currenttimemillis. I think I was a bit tired when coding that.. Sometimes coding is not about how good u actually are at coding, but how smart and awake you are, isn't it?
    Thanks! :^)
Thread Status:
Not open for further replies.

Share This Page