Pergunta

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

Foi útil?

Solução

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.

Outras dicas

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);

}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top