Date format

i don't understand why this will format all my dates except the month of sept... any suggestions?

Format df =new SimpleDateFormat(" MMMM dd yyyy hh:mm a");

DateFormat df2 = DateFormat.getDateInstance(DateFormat.MEDIUM);

Date d1 = df.parse(editrow[first][0]);

newDate = df2.format(d1);

i use July 31 2007 10:00 AM....Aug 14 2007 9:00 PM......Oct 26 2007 9:00 PM ...ect but it errors on Sept 15 2007 7:00 AM

[502 byte] By [mark07a] at [2007-11-27 11:56:58]
# 1

What error does it give?

You probably need "Sep" or "September".

doremifasollatidoa at 2007-7-29 19:10:34 > top of Java-index,Java Essentials,Java Programming...
# 2

java.text.ParseException: Unparseable date: " Sept 2 2007 2:00 AM"

that's what i was thinking but can i parse Sept somehow?

mark07a at 2007-7-29 19:10:34 > top of Java-index,Java Essentials,Java Programming...
# 3

You could use the DateFormatSymbols class to modify the ShortMonth Strings.

http://java.sun.com/j2se/1.4.2/docs/api/java/text/DateFormatSymbols.html

doremifasollatidoa at 2007-7-29 19:10:34 > top of Java-index,Java Essentials,Java Programming...
# 4

import java.text.*;

import java.util.*;

public class FormatExample {

public static void main(String[] args) throws ParseException {

DateFormatSymbols symbols = DateFormatSymbols.getInstance(); //1.6

String[] months = symbols.getShortMonths();

System.out.println(Arrays.toString(months));

months[8]="Sept";

symbols.setShortMonths(months);

String[] data = {

"July 31 2007 10:00 AM",

"Aug 14 2007 9:00 PM",

"Oct 26 2007 9:00 PM",

"Sept 15 2007 7:00 AM"

};

DateFormat df = new SimpleDateFormat("MMMM dd yyyy hh:mm a", symbols);

DateFormat df2 = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM);

for(String s : data) {

Date d = df.parse(s);

System.out.format("%s --> %s%n", s, df2.format(d));

}

}

}

ParvatiDevia at 2007-7-29 19:10:34 > top of Java-index,Java Essentials,Java Programming...
# 5

I looked in the sourcecode of SimpleDateFormat

if the placeholder for Month is MMM or MMMM they try to match first the full monthname and then the short form (3 letter only), thats why Juli and Aug worked, but Sept not.

Franco

franco_weichela at 2007-7-29 19:10:34 > top of Java-index,Java Essentials,Java Programming...