Simple parsing SimpleDateFormat (String s) gives wrong date
As an input, I have a Date object (exDate = Fri Aug 01 00:00:00 EEST 2014) that needs to be formed. After parsing the date, I am getting the 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
01-Aug-2014 12.00.00.000000000 AM
and resut, dateF will be
Sun Dec 29 00:00:00 EET 2013
So after parsing the date string, the result is wrong. Maybe anyone knows the source of the problem? Or another way to format the date in a different one SimpleDateFormat
?
+3
source to share
1 answer
The problem is YYYY which means :
Y Week year;
The actual year you are looking for will be yyyy
.
I really recommend that you follow the link above to see the full list.
You should also replace milliseconds with .SSS
as you cannot get a more accurate value.
+1
source to share