Solved Getting Date Using System

Discussion in 'Plugin Development' started by travja, Oct 22, 2012.

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

    travja

    I am just trying to get the date + hour + minute out of the system... I am currently trying to use:
    Date date = new Date(System.currentTimeMillis()); but obviously that doesn't work... Can someone help me figure out how to convert the time in milliseconds to a day, an hour, and a minute... This is the first time I have been messing with dates so I am really kind of confused... This is going to be for a temp. ban sort of feature... I don't really need the info too soon but it would be nice if you guys could help me out! Thanks!
     
  2. Offline

    KeybordPiano459

    Well first of all, does that print milliseconds since the day started? If so, try something off the top of my head like this:
    Code:java
    1. int s;
    2. int m;
    3. int h;
    4. if (date>1000) {
    5. s++;
    6. }
    7. if (s>60) {
    8. m++;
    9. }
    10. if (m>60) {
    11. h++;
    12. }
    13. System.out.println(h+":"+m+"s");
     
  3. Offline

    skore87

    You don't actually need to pass it any parameters to get the current time. If you want to use a time you wrote to a file, you could use the LONG datatype to input into that constructor if you preferred although there are other ways to do it.
     
  4. Offline

    travja

    System.currentTimeMillis(); prints the milliseconds since January 1st 1970 or something..... I just need to find an easy way to get the date and time of the console... it does print it before every log... I just don't know how to get it.
    I am wanting to print it to a file for a temp-ban... but I don't know how to find the date and time... as stated above.
     
  5. Offline

    KeybordPiano459

  6. Offline

    travja

    That still doesn't solve my problem of getting the actual time and day.... Would I use date.getMonth() .getDate() and so on?
     
  7. Offline

    Sagacious_Zed Bukkit Docs

  8. Offline

    zack6849

    I use this.
    Code:
    String time = String.format("[%tm/%td/%ty - %tH:%tM:%tS] ", new Date(), new Date(),new Date(),new Date(),new Date(),new Date());
    
    so the format it would print is "[10/24/12 - 01:01:56] "
    Note: you need to make a new date every time you want it, so you cant just create the string once when the plugin loads, or the time will stay the same.
     
  9. Offline

    Sagacious_Zed Bukkit Docs

    You really should not need to make a new date, it really should work if you give the same date for each format variable
     
  10. Offline

    travja

    So it would automatically convert the strings to the date?
     
  11. Offline

    Sagacious_Zed Bukkit Docs

    No the above code snippet shared by zack turns a date's value into a string.
     
  12. Offline

    lenis0012

    for the current miles:
    Code:
    public void sendMS(Player player)
    {
       player.sendMessage(String.valueOf(new Date().getTime());
    }
    
    for the date:
    Code:
    Calendar cal = Calendar.getInstance();
    int hours = cal.get(Calendar.HOUR_OF_DAY);
    int minutes = cal.get(Calendar.MINUTES);
    int seconds = cal.get(Calendar.SECOND);
    String ap = " AM";
    if(hours > 12)
        ap = " PM";
     
    String time = String.valueOf(hours) + ":" + String.valueOf(minutes) + ap;
    
     
  13. Offline

    exload

  14. Offline

    travja

    What I did was used new Date().getTime(); and added 5 days... went from there, Solved!
     
Thread Status:
Not open for further replies.

Share This Page