Issues with date?

Discussion in 'Plugin Development' started by NerdsWBNerds, Feb 2, 2013.

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

    NerdsWBNerds

    So here is my code...

    Code:
     
    String d = "";
     
    DateFormat dateFormat = new SimpleDateFormat("MM-DD-YYYY");
       dateFormat.setTimeZone(TimeZone.getTimeZone("CST"));
    Date date = new Date();
     
    d = dateFormat.format(date);
     
    
    Here is the issue, in January it was working fine, 1-21-2013, 1-22-2013, etc but the issue is that in February the day didn't go back to 1. It's just been 2-32-2013 (on the 1st) 2-33-2013 (today)

    How do I fix that?
     
  2. Offline

    HollowCube

    The capitalization of the DateFormat pattern is incorrect. A capital "DD" returns the day of the current year, whereas a lowercase "dd" returns the day of the current month. Changing the pattern should make it return the desired output. The following website contains a chart listing all of the available date and time patterns:

    http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
     
Thread Status:
Not open for further replies.

Share This Page