Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SimpleDateFormat function parse(String s) gives wrong date

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?

like image 204
Viktoriia Avatar asked Feb 05 '26 10:02

Viktoriia


1 Answers

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.

like image 77
Mansueli Avatar answered Feb 08 '26 02:02

Mansueli