Compare Dateformat (dd-MM-yyyy HH:mm:ss)

Discussion in 'Plugin Development' started by edocsyl, May 15, 2012.

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

    edocsyl

    Hi

    I wanna compare two dates, how can i do this. I alrdy made this with only dates but i need to do this with date and time.

    Andy ideas, links etc?

    Greez Edocsyl
     
  2. Offline

    Kanlaki101

    If you're wanting to just see if a date has passed (for a ban plugin, etc), it's pretty simple, actually.

    Just get the current time in milliseconds (returns a long), and compare it to another date (which needs to be in the form of a long). Comparing it will return an integer. If that integer is >=0, the time has passed.
     
  3. Offline

    edocsyl

    But i dont have the timestap.. I take this values out of a database..

    Like so: 15-02-2012 20:22:15
     
  4. Offline

    Kanlaki101

    What exactly are you trying to do, and where do you get your two dates?

    EDIT: Just had to read the post again (:confused:).

    Do you need to get the exact time between the dates? What?
     
  5. Offline

    Double0negative

    Code:
    DateFormat format = new SimpleDataFormat("dd-MM-yyyy HH:mm:ss");
    Date date = (Date)format.parse(yourdate);
    long time = date.getTime();
    
    Gives you a millisecond timestamp to work with
     
  6. Offline

    edocsyl

    Code:
     
        public long getTimeStamp(String strDate) throws Exception{
            DateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            Date date = (Date)format.parse(strDate);
            long time = date.getTime();
            return time;
        }
    
     
Thread Status:
Not open for further replies.

Share This Page