views:

41

answers:

2

I'm using a java based tool and there's a config option for a dateformat which I've set to "MM/dd/yy hh:mma" but it's apparently expected 'am' or 'pm', not 'a' or 'p' because the input dates aren't being recognized. e.g. 12/31/2008 3:28p

Is there such a SimpleDateFormat specification for this particular format? (Assumption on my part that this Java method is being utilized.) I'll ask the tool vendor next but SO seems to be 'the' place to go!

TIA

+2  A: 

This is not the answer you want to hear, but I'm afraid, if you are only allowed to enter the dateformat, there's nothing much you can do about it, unless you can somehow append a 'M'. Based on the example in the javadoc for SimpleDateFormat, a single 'a' accepts either AM or PM.

limc
After looking further, it appears you are correct.
Darian Miller
+3  A: 

you can do this

public static void main(String[] args) throws ParseException {
    DateFormatSymbols instance = DateFormatSymbols.getInstance();
    instance.setAmPmStrings(new String[]{"a","p"});
    SimpleDateFormat format = new SimpleDateFormat("MM/dd/yy hh:mma",instance);
    Date parsedDate = format.parse("12/31/2008 3:28p");
    System.out.println(parsedDate);

}
Shekhar
That will work, but from the sound of it the asker does not have control of the code base; only an option setting the format. And the vendor would probably not want to make this change, because that would break any users who are using "AM" and "PM".
jdmichal
hmmm..yup that will be a problem..
Shekhar
Thanks, but it's a config file, no source access.
Darian Miller