1

I have a SimpleDateFormat like this :

SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");

and trying to parse such 2012-Jul-29 17:14:39 but I`m getting

java.text.ParseException: Unparseable date: "2012-Jul-29 17:14:39" at java.text.DateFormat.parse(Unknown Source) at com.sysplan.visixd.blastgauge.BGParser.main(Parser.java:396)

Any idea why ?

2
  • 7
    try new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss", Locale.ENGLISH); Commented May 17, 2013 at 10:07
  • It is working fine for me. Can you share the complete code? Commented May 17, 2013 at 10:09

4 Answers 4

3

It appears to be a locale problem, I tried this without any error

new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss").parse("2012-Jul-29 17:14:39");

However this failed:

new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss", Locale.TAIWAN)
        .parse("2012-Jul-29 17:14:39");

So it appears to be a locale problem, you need to specify your locale to ENGLISH

new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss", Locale.ENGLISH)
        .parse("2012-Jul-29 17:14:39");

That is:

SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(
        "yyyy-MMM-dd HH:mm:ss", Locale.ENGLISH);
Sign up to request clarification or add additional context in comments.

7 Comments

Why can't it be an automatic locale?
@IgorGanapolsky The automatic one depends on the user's environment and is not necessarily Locale.ENGLISH.
Why are you assuming that it needs to be ENGLISH?
@IgorGanapolsky Which thing needs to be ENGLISH?
@IgorGanapolsky Mine(Taiwan) and obviously OP's.
|
1

Try this

SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss", Locale.ENGLISH);

Comments

0

try this

new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss", Locale.ENGLISH);

Comments

0

You can use next code:

import java.text.DateFormat;
import java.util.Calendar;

public static void main(String[] args) {
        // TODO Auto-generated method stub

Calendar now = Calendar.getInstance();
DateFormat formateadorFechaMedia = DateFormat.getDateInstance(DateFormat.MEDIUM);
System.out.println(formateadorFechaMedia.format(now.getTime()));

}
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.