I need to parse a String that does not originally have the year set like "13 Aug 11:30"
but when I output the date it adds the year on, I tried set year but the year is totally wrong the output comes as "Thu Aug 13 11:30:00 GMT 3911"
Is there a way to set the year after the date is parsed?
SimpleDateFormat formatter = new SimpleDateFormat("dd MMM HH:mm");
String dateStr = "13 Aug 11:30";
Date fromDate = (Date)formatter.parse(dateStr);
fromDate.setYear(2011);
Use Calendar
to set the year:
Calendar c = Calendar.getInstance();
c.setTime(fromDate);
c.set(Calendar.YEAR, 2011);
fromDate = c.getTime();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With