3

As an input I have Date object(for example, exDate=Fri Aug 01 00:00:00 EEST 2014) that must be formated. After the parsing of the date, I get wrong date.

            SimpleDateFormat sdf = new SimpleDateFormat(
                    "dd-MMM-YYYY hh.mm.ss.SSSSSSSSS aa", Locale.ENGLISH);
            String dateStart = sdf.format(exDate);
            Date dateF = sdf.parse(dateStart);

dateStart will be equal to

01-Aug-2014 12.00.00.000000000 AM 

and the resut, dateF will be equal to

Sun Dec 29 00:00:00 EET 2013

So, after the parsing of a string with date, the result is wrong. Maybe, somebody know the source of the problem? Or another way to format date in another SimpleDateFormat?

jmj
  • 237,923
  • 42
  • 401
  • 438
Viktoriia
  • 2,290
  • 4
  • 16
  • 17

1 Answers1

1

The problem is the YYYY which means:

 Y   Week year;

The actual year, which is what you are looking for would be yyyy.

I really recommend that you go in the link above to see the full list.

You should also replace the milliseconds to .SSS as you can't get more precise than that.

Community
  • 1
  • 1
Mansueli
  • 6,223
  • 8
  • 33
  • 57
  • 2
    Or go to the [ultimate authority](http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns). (Though I don't know if SDF honors all those variations.) – Hot Licks Aug 20 '14 at 17:08