James James - 3 months ago 8x
Java Question

how to get any specific date of current year

Hi I was wondering if there was any way using Jav's Date class or and Joda Time classes to get any specific day of this year. For example if I want the date

. The reason why this is a problem is because I am giving a string representation of someone's birthday lets say
and I want to convert this to be a Date which has
month 12 day 31 and year 2013

Can anyone help me on this?

I am using the DateMidnight Joda time class and I parse the string into a date using Simple Formatter but I was wondering if there was any way to set the year to be a specific year.


If you want to implement using JodaTime you can do as below. Format using DateTimeFormatter to get DateTime and then with DateTime#withYear(int) method, year can be changed.

String dob = "12311991";
DateTimeFormatter fmt = DateTimeFormat.forPattern("MMddyyyy");
DateTime dt = fmt.parseDateTime(dob).withYear(2013);